(function($) {
	if(!document.defaultView || !document.defaultView.getComputedStyle){ // IE6-IE8
		var oldCurCSS = jQuery.curCSS;
		jQuery.curCSS = function(elem, name, force){
			if(name === 'background-position'){
				name = 'backgroundPosition';
			}
			if(name !== 'backgroundPosition' || !elem.currentStyle || elem.currentStyle[ name ]){
				return oldCurCSS.apply(this, arguments);
			}
			var style = elem.style;
			if ( !force && style && style[ name ] ){
				return style[ name ];
			}
			return oldCurCSS(elem, 'backgroundPositionX', force) +' '+ oldCurCSS(elem, 'backgroundPositionY', force);
		};
	}
	
	var oldAnim = $.fn.animate;
	$.fn.animate = function(prop){
		if('background-position' in prop){
			prop.backgroundPosition = prop['background-position'];
			delete prop['background-position'];
		}
		if('backgroundPosition' in prop){
			prop.backgroundPosition = '('+ prop.backgroundPosition;
		}
		return oldAnim.apply(this, arguments);
	};
	
	function toArray(strg){
		strg = strg.replace(/left|top/g,'0px');
		strg = strg.replace(/right|bottom/g,'100%');
		strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
		var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
		return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
	}
	
	$.fx.step. backgroundPosition = function(fx) {
		if (!fx.bgPosReady) {
			var start = $.curCSS(fx.elem,'backgroundPosition');
			
			if(!start){//FF2 no inline-style fallback
				start = '0px 0px';
			}
			
			start = toArray(start);
			
			fx.start = [start[0],start[2]];
			
			var end = toArray(fx.options.curAnim.backgroundPosition);
			fx.end = [end[0],end[2]];
			
			fx.unit = [end[1],end[3]];
			fx.bgPosReady = true;
		}
		//return;
		var nowPosX = [];
		nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
		nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];           
		fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

	};
})(jQuery);

$(document).ready(function() {

	$( "#logo" ).mouseover(function(){
        $(this).stop().animate({'margin-left':'5px'},{queue:false, duration:300, easing: 'easeOutElastic'}) 
	});
	$( "#logo" ).mouseout(function(){ 
        $(this).stop().animate({'margin-left':'15px'},{queue:false, duration:500, easing: 'linear'})  
    }); 
	
	$('#image div').fadeIn(3000, function() { });

	//$("#surface_form").validate({});
	$("#gf1_form").validate();
	$("#surface_form").validate({
		meta: "validate",
		errorLabelContainer: $("#surface_form div.surface_error")
	});
	
	$("#reset").click(function() {
			v.resetForm();
	});
	/*
	$( "div#nav ul li a" ).mouseover(function(){
		$(this)
		.dequeue()
		.animate({backgroundPosition:'25px 40px'},{duration:200, easing: 'easeInQuint'})
		.animate({backgroundPosition:'25px -20px'},0)
		.animate({backgroundPosition:'25px 8px'},{duration:300, easing: 'easeOutQuint'});
	});
	*/
	
	$( "#leftmenu li a:not(.current)" ).mouseover(function(){
        $(this).stop().animate({'text-indent':'18px', 'background-color':'#ccc'},{queue:false, duration:200, easing: 'easeOutQuint'})
	});
    $( "#leftmenu li a:not(.current)" ).mouseout(function(){ 
        $(this).stop().animate({'text-indent':'8px','background-color':'#eee'},{queue:false, duration:300, easing: 'linear'});
    });
	
	$( "#leftmenu2 li.lightpink a:not(.current)" ).mouseover(function(){
        $(this).stop().animate({'text-indent':'18px', 'background-color':'#ab3f63'},{queue:false, duration:200, easing: 'easeOutQuint'})
	});
    $( "#leftmenu2 li.lightpink a:not(.current)" ).mouseout(function(){ 
        $(this).stop().animate({'text-indent':'8px', 'background-color':'#DC82A0'},{queue:false, duration:300, easing: 'linear'});
    });

	$( "#content table.home td a" ).mouseover(function(){
        $(this).stop().animate({'color':'#000'},{queue:false, duration:300, easing: 'linear'}) 
	});
    $( "#content table.home td a" ).mouseout(function(){ 
        $(this).stop().animate({'color':'#828282'},{queue:false, duration:1000, easing: 'linear'})  
    });

	//Load the slideshow
	theRotator();
	$('div.rotator ul').fadeIn(3000);
    $('div.rotator ul li').fadeIn(3000); // tweek for IE
});

function theRotator() {
	$('div.rotator ul li').css({opacity: 0.0});
	$('div.rotator ul li:first').css({opacity: 1.0});
	setInterval('rotate()',6000);	
}

function rotate() {	
	var current = ($('div.rotator ul li.show')?  $('div.rotator ul li.show') : $('div.rotator ul li:first'));

    if ( current.length == 0 ) current = $('div.rotator ul li:first');

	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div.rotator ul li:first') :current.next()) : $('div.rotator ul li:first'));

	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 2000);

	//Hide the current image
	current.animate({opacity: 0.0}, 2000)
	.removeClass('show');
};

/**
 * @author Alexander Farkas
 * v. 1.21
 */
