/* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+  <http://cherne.net/brian/resources/jquery.hoverIntent.html>*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:2,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);

// Fix clear type on MSIE
jQuery.fn.fixClearType = function(){return this.each(function(){if(typeof this.style.filter  && this.style.removeAttribute)this.style.removeAttribute("filter");})}

// July 2009 - Sean Ockert - http://catalyticat.com
var Crossfade = function() {

		var timeout = 500;
		var slideDist = 12; //px
		var bgColor = '#eee';
		var borderColor = '#8D1B1B';
		var current = 1; // First image
		
		//panLeft = parseInt($('#imageframe > li > div').css('marginLeft'))+slidedist;
		$('#imageframe').children().hide();
	
		fader(current); //initialise
		
		$('#fadein > div').hoverIntent( // Hover intent sensitivity can be adjusted
			function(){
				selected = $(this).attr('id');
				if (selected != current) { // Don't trigger fade if the current is hovered over
					fader(selected);
				}
			},      
			function () {}
		);

		//  Fades out the current image and fades in a new one. It also animates the caption to slide to the right
		function fader(selected){
			// Fade div backgrounds			
			$('#'+current).css({backgroundColor:'#fff',borderBottomColor:'#eee'});
			$('#'+selected).animate({backgroundColor:bgColor,borderBottomColor:borderColor}, timeout);	
			
			$('#img'+current)
				.fadeOut(timeout)
				.children('.caption')
					.stop()
					.css({marginLeft:0,opacity:0}); // Return caption to its original position (otherwise it wont animate)
					
			$('#img'+selected)
				.fadeIn(timeout)
				.children('.caption')
					.animate({marginLeft:slideDist,opacity:0.99}, {duration: timeout*3,easing: 'easeOutCubic'})
					.fixClearType(); 
					
			current = selected; // Set the current id to the selected id
		}
}


$(window).load(function(){
    //$('#img4').attr('src', 'img/china2.jpg').load(function() {  
    //    alert('Image Loaded');  
    //});  
	// Initialise the crossfade
	Crossfade();	
});

/* Copyright © 2001 Robert Penner */
jQuery.extend(jQuery.easing,
{
	def: 'easeOutCubic',
	swing: function (x, t, b, c, d) {
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},	
	easeOutCubic: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t + 1) + b;
	}
});

/* jQuery Color Animations
 * Copyright 2007 John Resig
 * Released under the MIT and GPL licenses. */
(function(jQuery){jQuery.each(['backgroundColor','borderBottomColor','borderLeftColor','borderRightColor','borderTopColor','color','outlineColor'],function(i,attr){jQuery.fx.step[attr]=function(fx){if(fx.state==0){fx.start=getColor(fx.elem,attr);fx.end=getRGB(fx.end);}
fx.elem.style[attr]="rgb("+[Math.max(Math.min(parseInt((fx.pos*(fx.end[0]-fx.start[0]))+fx.start[0]),255),0),Math.max(Math.min(parseInt((fx.pos*(fx.end[1]-fx.start[1]))+fx.start[1]),255),0),Math.max(Math.min(parseInt((fx.pos*(fx.end[2]-fx.start[2]))+fx.start[2]),255),0)].join(",")+")";}});function getRGB(color){var result;if(color&&color.constructor==Array&&color.length==3)
return color;if(result=/rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color))
return[parseInt(result[1]),parseInt(result[2]),parseInt(result[3])];if(result=/rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color))
return[parseFloat(result[1])*2.55,parseFloat(result[2])*2.55,parseFloat(result[3])*2.55];if(result=/#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color))
return[parseInt(result[1],16),parseInt(result[2],16),parseInt(result[3],16)];if(result=/#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color))
return[parseInt(result[1]+result[1],16),parseInt(result[2]+result[2],16),parseInt(result[3]+result[3],16)];return colors[jQuery.trim(color).toLowerCase()];}
function getColor(elem,attr){var color;do{color=jQuery.curCSS(elem,attr);if(color!=''&&color!='transparent'||jQuery.nodeName(elem,"body"))
break;attr="backgroundColor";}while(elem=elem.parentNode);return getRGB(color);};var colors={brown:[139,72,42],};})(jQuery);