// JavaScript Document


// IE ANCHOR BG CACHE

var version = navigator.appVersion;
	version = version.substring(0,1);
var browser = navigator.appName;

if (browser =="Microsoft Internet Explorer"){
	try {
		document.execCommand("BackgroundImageCache", false, true);
	} catch(e) {}
}

// FOCUS INPUT
var colorful = new ColorfulInput;
	colorful.skip = ['submit'];
	colorful.skip = ['reset'];
	colorful.color['focus'] = '#FFFFEE';

window.onload = function() {
	colorful.set();
}

function ColorfulInput() {
	this.skip= [];
	this.color = { 'blur': '', 'focus': '#FFFFEE' };

	this.set = function() {
	for (var i = 0; i < document.forms.length; i++) {
		for (var f = 0; f < document.forms[i].length; f++) {
			var elm = document.forms[i][f];
			if(!this._checkSkip(elm)) continue;
			this._setColor(elm, 'focus');
			this._setColor(elm, 'blur');
		}
	}
}

this._checkSkip = function(elm) {
	for(var i in this.skip) {
 		if(elm.type == this.skip[i]) return false;
	}
	return true;
}

this._setColor = function(elm, type) { 
	var color = this.color[type];
	var event = function() { elm.style.backgroundColor = color; };
	if(elm.addEventListener) {
		elm.addEventListener(type, event, false);
	}else if(elm.attachEvent) {
		elm.attachEvent('on'+type, event);
	}else{
		elm['on'+type] = event;
	}
}
}

// OPEN WINDOW
function openwin(url) {
 colors = window.open(url, 'colors','width=660,height=680,scrollbars=yes,resizable=yes');
 colors.focus();
}

// ALPHA PNG IE

/*--------------------------------------------------------------------------*
 *  
 *  alphafilter JavaScript Library beta3
 *  
 *  MIT-style license. 
 *  
 *  2007 Kazuma Nishihata 
 *  http://www.webcreativepark.net
 *  
 *--------------------------------------------------------------------------*/

new function(){

	if(window.addEventListener){
		window.addEventListener('load',alphafilter,false);
	}else if(window.attachEvent){
		window.attachEvent('onload',alphafilter);
	}
	
	function alphafilter(){
		if (typeof document.body.style.maxHeight == "undefined") {//for old ie
			var elements = getElementsByClassName("alphafilter");
			for (var i=0; i<elements.length; i++) {
				var element = elements[i];
				if(element.nodeName=="IMG"){
					var newimg  = document.createElement("b");
					newimg.id   = element.id;
					newimg.className     = element.className;
					newimg.style.display = "block";
					newimg.style.width   = element.width;
					newimg.style.height  = element.height;
					newimg.style.float   = element.align;
					newimg.style.filter  = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src="+element.src+",sizingMethod='scale')";
					element.parentNode.replaceChild(newimg,element);
				}else{
					var anchors = element.getElementsByTagName("a");
					for (var j=0; j<anchors.length; j++) {
						var anchor = anchors[j];
						anchor.style.position="relative";
					}
					var  newimg = element.currentStyle.backgroundImage || element.style.backgroundImage;
					newimg.match(/^url[("']+(.*\.png)[)"']+$/i)
					var newimg = RegExp.$1;
					element.style.filter ="progid:DXImageTransform.Microsoft.AlphaImageLoader(src="+newimg+",sizingMethod='image')";
					element.style.background = "none";
				}
			}
		}
	}
	
	function getElementsByClassName(className){
		var i, j, eltClass;
		var objAll = document.getElementsByTagName ? document.getElementsByTagName("*") : document.all;
		var objCN = new Array();
		for (i = 0; i < objAll.length; i++) {
			eltClass = objAll[i].className.split(/\s+/);
			for (j = 0; j < eltClass.length; j++) {
				if (eltClass[j] == className) {
					objCN.push(objAll[i]);
					break;
				}
			}
		}
		return objCN;
	}
}

// minmax.js:
// minmax.js: make IE5+/Win support CSS min/max-width/height
// version 1.0, 08-Aug-2003
// written by Andrew Clover <and@doxdesk.com>, use freely

/*@cc_on
@if (@_win32 && @_jscript_version>4)

var minmax_elements;

minmax_props= new Array(
  new Array('min-width', 'minWidth'),
  new Array('max-width', 'maxWidth'),
  new Array('min-height','minHeight'),
  new Array('max-height','maxHeight')
);

// Binding. Called on all new elements. If <body>, initialise; check all
// elements for minmax properties

function minmax_bind(el) {
  var i, em, ms;
  var st= el.style, cs= el.currentStyle;

  if (minmax_elements==window.undefined) {
    // initialise when body element has turned up, but only on IE
    if (!document.body || !document.body.currentStyle) return;
    minmax_elements= new Array();
    window.attachEvent('onresize', minmax_delayout);
    // make font size listener
    em= document.createElement('div');
    em.setAttribute('id', 'minmax_em');
    em.style.position= 'absolute'; em.style.visibility= 'hidden';
    em.style.fontSize= 'xx-large'; em.style.height= '5em';
    em.style.top='-5em'; em.style.left= '0';
    if (em.style.setExpression) {
em.style.setExpression('width', 'minmax_checkFont()');
document.body.insertBefore(em, document.body.firstChild);
    }
  }

  // transform hyphenated properties the browser has not caught to camelCase
  for (i= minmax_props.length; i-->0;)
    if (cs[minmax_props[i][0]])
st[minmax_props[i][1]]= cs[minmax_props[i][0]];
  // add element with properties to list, store optimal size values
  for (i= minmax_props.length; i-->0;) {
    ms= cs[minmax_props[i][1]];
    if (ms && ms!='auto' && ms!='none' && ms!='0' && ms!='') {
st.minmaxWidth= cs.width; st.minmaxHeight= cs.height;
minmax_elements[minmax_elements.length]= el;
// will need a layout later
minmax_delayout();
break;
  } }
}

// check for font size changes

var minmax_fontsize= 0;
function minmax_checkFont() {
  var fs= document.getElementById('minmax_em').offsetHeight;
  if (minmax_fontsize!=fs && minmax_fontsize!=0)
    minmax_delayout();
  minmax_fontsize= fs;
  return '5em';
}

// Layout. Called after window and font size-change. Go through elements we
// picked out earlier and set their size to the minimum, maximum and optimum,
// choosing whichever is appropriate

// Request re-layout at next available moment
var minmax_delaying= false;
function minmax_delayout() {
  if (minmax_delaying) return;
  minmax_delaying= true;
  window.setTimeout(minmax_layout, 0);
}

function minmax_stopdelaying() {
  minmax_delaying= false;
}

function minmax_layout() {
  window.setTimeout(minmax_stopdelaying, 100);
  var i, el, st, cs, optimal, inrange;
  for (i= minmax_elements.length; i-->0;) {
    el= minmax_elements[i]; st= el.style; cs= el.currentStyle;

    // horizontal size bounding
    st.width= st.minmaxWidth; optimal= el.offsetWidth;
    inrange= true;
    if (inrange && cs.minWidth && cs.minWidth!='0' && cs.minWidth!='auto' && cs.minWidth!='') {
st.width= cs.minWidth;
inrange= (el.offsetWidth<optimal);
    }
    if (inrange && cs.maxWidth && cs.maxWidth!='none' && cs.maxWidth!='auto' && cs.maxWidth!='') {
st.width= cs.maxWidth;
inrange= (el.offsetWidth>optimal);
    }
    if (inrange) st.width= st.minmaxWidth;

    // vertical size bounding
    st.height= st.minmaxHeight; optimal= el.offsetHeight;
    inrange= true;
    if (inrange && cs.minHeight && cs.minHeight!='0' && cs.minHeight!='auto' && cs.minHeight!='') {
st.height= cs.minHeight;
inrange= (el.offsetHeight<optimal);
    }
    if (inrange && cs.maxHeight && cs.maxHeight!='none' && cs.maxHeight!='auto' && cs.maxHeight!='') {
st.height= cs.maxHeight;
inrange= (el.offsetHeight>optimal);
    }
    if (inrange) st.height= st.minmaxHeight;
  }
}

// Scanning. Check document every so often until it has finished loading. Do
// nothing until <body> arrives, then call main init. Pass any new elements
// found on each scan to be bound   

var minmax_SCANDELAY= 500;

function minmax_scan() {
  var el;
  for (var i= 0; i<document.all.length; i++) {
    el= document.all[i];
    if (!el.minmax_bound) {
el.minmax_bound= true;
minmax_bind(el);
  } }
}

var minmax_scanner;
function minmax_stop() {
  window.clearInterval(minmax_scanner);
  minmax_scan();
}

minmax_scan();
minmax_scanner= window.setInterval(minmax_scan, minmax_SCANDELAY);
window.attachEvent('onload', minmax_stop);

@end @*/


/*
 * yuga.js 0.1.0
 *
 * Copyright (c) 2006 Kyosuke Nakamura (kyosuke.jp)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * Since: 2006-10-30
 * Modified:2006-11-15

*/


// YUGA JS


var yuga = {
	preloader: {
		loadedImages: [],
		load: function (url){
			var img = this.loadedImages;
			var l = img.length;
			img[l] = new Image();
			img[l].src = url;
			}
	},
	uri: {
		dirName: function(uri){
			var ary = uri.split('/');
			ary.pop();
			return ary.join('/');
		},
		path: function (uri){
			return uri.split('#')[0];
		},
		anchorName: function (uri){
			return uri.split('#')[1];
		},
		isSelfLink: function(href){
			return ((this.path(href) == this.path(location.href)) || (this.path(href) == this.dirName(location.href)+'/') || (this.path(href) == this.dirName(location.href)));
		}
	}
};


$(function(){
	//ROLLOVER IMAGE
	$('a img.roll_over,#contents a img,#header ul a img').each(function(){
		this.originalSrc = this.src;
		this.rolloverSrc = this.originalSrc.replace(/(\.gif|\.jpg|\.png)/, "_on$1");
		yuga.preloader.load(this.rolloverSrc);
	}).hover(function(){
		this.src = this.rolloverSrc;
	},function(){
		this.src = this.originalSrc;
	});
	//NOW PAGE IMAGE
	$('#contents a,#header ul a').each(function(){
		if (yuga.uri.isSelfLink(this.href) && !yuga.uri.anchorName(this.href)) {
			$(this).addClass('current');
			$(this).find('img').each(function(){
				$(this).unbind('mouseover');
				$(this).unbind('mouseout');
				this.currentSrc = this.getAttribute('src').replace(/(\.gif|\.jpg|\.png)/, "_on$1");
				this.src = this.currentSrc;
			});
		}
	});

	

	//OTHER SITES BLANK WINDOW
	/*$('a[@href^="http://"]').not('[@href^="http://localhost/"]').click(function(){
		window.open(this.href, '_blank');
		return false;
	}).addClass('externalLink');*/
	
	//EASING SCROLL PAGE ANCHOR
	$('a[@href^="#"]').click(function(){
		var href = yuga.uri.anchorName(this.href);
		$('#'+href).ScrollTo(500,'easeout');
		return false;
	});
	$('area[@href^="#"]').click(function(){
		var href = yuga.uri.anchorName(this.href);
		$('#'+href).ScrollTo(500,'easeout');
		return false;
	});
});
	//PHOTO GALLARY
jQuery(function(){
   jQuery("div.svw").prepend("<img src='../img/parts/svwloader.gif' class='ldrgif' alt='loading...'/ >"); 
});
var j = 0;
jQuery.fn.slideView = function(settings) {
	  settings = jQuery.extend({
     easeFunc: "easeInOutExpo", /* <-- easing function names changed in jquery.easing.1.2.js */
     easeTime: 750,
     toolTip: false
  }, settings);
	return this.each(function(){
		var container = jQuery(this);
		container.find("img.ldrgif").remove(); // removes the preloader gif
		container.removeClass("svw").addClass("stripViewer");		
		var pictWidth = container.find("li").find("img").width();
		var pictHeight = container.find("li").find("img").height();
		var pictEls = container.find("li").size();
		var stripViewerWidth = pictWidth*pictEls;
		container.find("ul").css("width" , stripViewerWidth); //assegnamo la larghezza alla lista UL	
		container.css("width" , pictWidth);
		container.css("height" , pictHeight);
		container.each(function(i) {
			jQuery(this).after("<div class='stripTransmitter' id='stripTransmitter" + j + "'><ul><\/ul><\/div>");
			jQuery(this).find("li").each(function(n) {
						jQuery("div#stripTransmitter" + j + " ul").append("<li><a title='" + jQuery(this).find("img").attr("alt") + "' href='#'><img src='img\/pht"+(n+1)+".jpg' \/><\/a><\/li>");												
				});
			jQuery("div#stripTransmitter" + j + " a").each(function(z) {
				jQuery(this).bind("click", function(){
				jQuery(this).addClass("current").parent().parent().find("a").not(jQuery(this)).removeClass("current"); // wow!
				var cnt = - (pictWidth*z);
				jQuery(this).parent().parent().parent().prev().find("ul").animate({ left: cnt}, settings.easeTime, settings.easeFunc);
				return false;
				   });
				});
			jQuery("div#stripTransmitter" + j).css("width" , pictWidth);
			jQuery("div#stripTransmitter" + j + " a:eq(0)").addClass("current");
			if(settings.toolTip){
			container.next(".stripTransmitter ul").find("a").Tooltip({
				track: true,
				delay: 0,
				showURL: false,
				showBody: false
				});
			}
			});
		j++;
  });	
};