/* Copyright (c) 2008 Kean Loong Tan http://www.gimiti.com/kltan
 * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * jFlow
 * Version: 1.1 (May 22, 2008)
 * Requires: jQuery 1.2+
 */
(function(A){
	A.fn.jFlow=function(D){
	var E=A.extend({},A.fn.jFlow.defaults,D);
	var F=0;var B=A(".jFlowControl").length;
	A(this).find(".jFlowControl").each(function(G){
		A(this).click(function(){
			A(".jFlowControl").removeClass("jFlowSelected");
			A(this).addClass("jFlowSelected");
			var H=Math.abs(F-G);
			
			frameW = getWidth();
			
			A(E.slides).animate({marginRight:"-"+(frameW*4-G*frameW+"px")},E.duration*(H));
			//A(E.slides).animate({marginRight:"-"+(5120-G*A(E.slides).find(":first-child").width()+"px")},E.duration*(H));
			//console.log(-(5120-G*A(E.slides).find(":first-child").width()));
			F=G})});
			
	A(E.slides).before('<div id="jFlowSlide"></div>').appendTo("#jFlowSlide");
	A(E.slides).find("div").each(function(){A(this).before('<div class="jFlowSlideContainer"></div>').appendTo(A(this).prev())});
	A(".jFlowControl").eq(F).addClass("jFlowSelected");
	var C=function(G){
		A("#jFlowSlide").css({position:"relative",width:E.width,height:E.height,overflow:"hidden"});
		A(E.slides).css({position:"relative",width:A("#jFlowSlide").width()*A(".jFlowControl").length+64+"px",height:A("#jFlowSlide").height()+"px",overflow:"hidden"});
		A(E.slides).children().css({position:"relative",marginRight:"16px",width:A("#jFlowSlide").width()+"px",height:A("#jFlowSlide").height()+"px","float":"right"});
		A(E.slides).children(':nth-child(1)').css({marginRight:"0"});
		A(E.slides).css({marginRight:"-"+(F*A(E.slides).find(":first-child").width()+"px")})
	};
	C();
	A(window).resize(function(){C()});
	A(".jFlowPrev").click(function(){
		if(F>0){F--}else{F=B-1}
		A(".jFlowControl").removeClass("jFlowSelected");
		A(E.slides).animate({marginRight:"-"+(F*A(E.slides).find(":first-child").width()+"px")},E.duration);
		A(".jFlowControl").eq(F).addClass("jFlowSelected")});
		A(".jFlowNext").click(function(){
			if(F<B-1){F++}else{F=0}
			A(".jFlowControl").removeClass("jFlowSelected");
			A(E.slides).animate({marginRight:"-"+(F*A(E.slides).find(":first-child").width()+"px")},E.duration);
			A(".jFlowControl").eq(F).addClass("jFlowSelected")}
		)
	};
A.fn.jFlow.defaults={easing:"swing",duration:400,width:"100%"}}
)
(jQuery);

function getWidth() {
  var myWidth = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
   
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
   
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
   
  }
  return myWidth;
  
}
