/*
 * @version 1.0
 */

jQuery(document).ready(function(){
	// Get current year
	/*now = new Date;
	theYear = now.getYear();
	if (theYear < 1900)	theYear = theYear+1900;
	$('#currentYear').html(theYear);*/
	

	//Cufont
	//Cufon.replace('h2', {});
	//
//	Cufon.replace('.font', {
//		hover:{color: '#ff0099' }
//	});	
//	Cufon.replace('.link_port', {
//		hover:{color: '#ff63c1' }
//	});	
	Cufon.replace('.title_percent', {
		fontWeight : 900 
	});
//	Cufon.replace('.topic_copy', {
//		fontWeight : 700 
//	});
//	Cufon.replace('.title', {
//		fontWeight : 400 
//	});
//	
//	Cufon.replace('.sidebar a', {
//		hover:{color: '#ff0099' }
//	});	
	
	
	
	// Navigation
	jQuery('.nav a')
		.each(function(){
			jQuery(this).append('<span></span>');
		})
		.not('.active').hover(
			function(){
				jQuery(this).find('span').stop(true, true).fadeIn(500);
			},
			function(){
				jQuery(this).find('span').stop(true, true).fadeOut(500);
			}
		);
		
	jQuery('.logo').hover(		
		function(){			
			jQuery(this).find('span').stop(true, true).fadeIn(500);			
		},
		function(){
			jQuery(this).find('span').stop(true, true).fadeOut(500);
		}
	);
	
	jQuery('.viewmore').hover(
		function(){
			jQuery(this).find('span').stop(true, true).animate({ paddingRight: '440px'}, 400, 'easeOutBounce');
		},
		function(){
			jQuery(this).find('span').stop(true, true).animate({ paddingRight: '0px'}, 400, 'easeOutCirc');
		}
	);
	
	
	// Home 
	if (jQuery('#page-home').html() != null){
		//rotateImg();
		//rotateImg_paging();
		//rotateBtn();
		ginslider();
		

		jQuery(".tweet").tweet({
			join_text: "auto",
			username: "sofreshdigital",							
			count: 2,
			auto_join_text_default: "we said",
			auto_join_text_ed: "we",
			auto_join_text_ing: "we were",
			auto_join_text_reply: "we replied",
			auto_join_text_url: "",
			loading_text: "loading tweets..."
		});

	};
	
	
	// Portfolio
	if (jQuery('#page-port').length > 0){		
		call_initPort();
		
		/*jQuery('.list_port li').live('mouseover', function(){	
			jQuery(this).find('rect').stop(true, true).animate({ 'stroke-width':"0" }, 75);
			jQuery(this).find('.title_port').stop(true, true).animate({ color:'#ff0099'});
		});
		jQuery('.list_port li').live('mouseout', function(){
			jQuery(this).find('rect').stop(true, true).animate({ 'stroke-width':"16" }, 75);
			jQuery(this).find('.title_port').stop(true, true).animate({ color:'#000000'});
		});*/
		
		jQuery('.list_port li').live('mouseover', portOver);
		jQuery('.list_port li').live('mouseout', portOut);
		
		
		
		var getPageHeight = jQuery('body').css('height');
			getPageHeight =getPageHeight.substring(0, getPageHeight.length-2);
			getPageNumb = Math.round(getDocumentSize(3)/getPageHeight);
			//alert(getPageNumb);
		for (var i=0; i<getPageNumb; i++){
			//alert(getPageHeight+'/'+getDocumentSize(3));
			var url_load = jQuery("#loadcontinues").val();			
			loadportfolio(url_load);
			url_load = "";
		}
	}
	
	
	// Portfolio detail
	if (jQuery('#page-port-detail').html() != null){
		/*rotateImg();
		rotateImg_paging();
		rotateBtn();*/
		ginslider();
		
		jQuery('.port_nav .l').hover(
			function(){
				//jQuery(this).stop(true,true).animate({ marginLeft:'-=40'});
				jQuery(this).stop(true,true).animate({ backgroundPosition:'-20px 50%'});
			},
			function(){
				//jQuery(this).stop(true,true).animate({ marginLeft:'+=40'});
				jQuery(this).stop(true,true).animate({ backgroundPosition:'0px 50%'});
			}
		);
		jQuery('.port_nav .r').hover(
			function(){
				//jQuery(this).stop(true,true).animate({ marginRight:'-=40'});
				jQuery(this).stop(true,true).animate({ backgroundPosition:'104% 50%'});
			},
			function(){
				//jQuery(this).stop(true,true).animate({ marginRight:'+=40'});
				jQuery(this).stop(true,true).animate({ backgroundPosition:'100% 50%'});
			}
		);
	};
	
	
	// Blog
	/*if (jQuery('.blog, .single ').html() != null){
		jQuery('.hentry').each(function(){
			jQuery(this).prepend( jQuery(this).find('.entry-content').find('a:first') );
			if (jQuery(this).find('.entry-content').find('p:first').html()=="")
				jQuery(this).find('.entry-content').find('p:first').remove();
		});
	}*/
	
	
	// Contact 
	if (jQuery('#page-contact').html() != null){
		//google.maps.event.addDomListener(window, 'load', initialize);
	}
	
	
	
	// The team
	if (jQuery('.banner_theTeam').html() != null){
		total = $('.banner_theTeam img').length;
					$('.banner_theTeam img').addClass('hide');
		  
		var index = {}, numbers = [];
		for (var i=0; i<18; ++i) {
			var number;
			do {
				number = randomInt(1, total-1);
			} while (index.hasOwnProperty("_"+number));
			index["_"+number] = true;
			numbers.push(number);			
		}
		delete index;
				
		for (var i=0; i<18; i++){
			var delay = 40;
			var c = i/3;
				c = Math.floor(c);
			var r = i%3;
				r = Math.floor(r);
			var id = String(c*120)+ String(r*104);
			//$('#ft').append( c*120 +'/'+ r*104 +' - ');
			//$('#hd').append( numbers[i] +' - ');
			$('.banner_theTeam img:eq('+numbers[i]+')').attr('class','show').addClass(id).css({ left: c*120, top: r*104}).delay(i*delay).fadeIn(750);
			
				/*var getSrcImg = $('.banner_theTeam img:eq('+numbers[i]+')').attr('src');			
				var Img = new Image();			
			
				Img.onerror = function(){
					return false;
				}		
				var src = getSrcImg;
				Img.onload = function(){ 
					 $('.banner_theTeam img:eq('+numbers[i]+')').attr('class','show').css({ left: c*120, top: r*104}).delay(i*delay).fadeIn(750);
					
					Img.onload=function(){};
				}	
				Img.src = src;*/
			
		}
		
		setTimeout("randomReplace()",10);
		
		
		$('.theTeam img').hover(
			function(){
				var getLeft = Number($(this).position().left)+50;
					getLeft = getLeft+ Number($(this).attr('lang'));
					
				var getTop = Number($(this).attr('longdesc'));				
				$('#sloganTip').css({ marginTop: getTop});
				//else $('#sloganTip').css({ top: '10'})
				
				var getSlogan = $(this).attr('alt');
				
				$('#sloganTip').html(getSlogan).css({ left: getLeft}).stop(true,true).animate({ top: '+=10', opacity:'1'});
				//$('#sloganTip').html(getSlogan).css({ left: getLeft}).stop(true,true).fadeIn();
			},
			function(){
				$('#sloganTip').stop(true,true).animate({ top: '-=10', opacity:'0'});
				//$('#sloganTip').stop(true,true).fadeOut();
			}
		);
		
		
		
		$('.theTeam_cover').jScrollHorizontalPane({scrollbarHeight:16, showArrows:true, arrowSize:10, wheelSpeed:0, resize: false, maintainPosition: false, reset: false});
		
	}
	
	
	
	
	// Santa claus	
	/*$('body').append('<img alt="" src="images/santa.gif" class="santa">')
	movingSanta();*/
});



/*function movingSanta(){
	var randomSanta = Math.floor(Math.random()* getDocumentSize(1));
	var randomDelay = Math.floor(Math.random()* 10000);	
	$('.santa').css({left:'-250px', top:randomSanta }).delay(randomDelay).animate({ left:getDocumentSize(0)+100}, 20000, function(){
		movingSanta();
	});
};*/



var autoContinueReplace;
var continueReplace = 0;
var total;
var teamI = 0;
function randomReplace(){
	/*var index = {}, numbers = [];
	for (var i=0; i<18; ++i) {
		var number;
		do {
			number = randomInt(1, 18);
		} while (index.hasOwnProperty("_"+number));
		index["_"+number] = true;
		numbers.push(number);			
	}
	delete index;*/			
	
	var zindex = 1;
	if (continueReplace<=total-19){
		//for (var i=0; i<3 ; i++){
			var randomnumber=Math.floor(Math.random()*18)
			//var nextItem = numbers[randomnumber];
			var c = randomnumber/3;
				c = Math.floor(c);
			var r = randomnumber%3;
				r = Math.floor(r);
			var id = String(c*120) + String(r*104);
			
			$('.banner_theTeam .hide:eq('+continueReplace+')').css({ left: c*120, top: r*104, zIndex:zindex}).fadeIn(1000, function(){
				$('.banner_theTeam img').each(function(){
					if ($(this).hasClass(id)){
						$(this).clone().appendTo('.waitingList').attr('class','');
						$(this).remove();
					}
				});
				$(this).addClass(id);
			});
			continueReplace++;
		//}
	}
	else{
		//$('.banner_theTeam img').attr('class','');
		//for (var i=0; i<3 ; i++){
			var randomnumber=Math.floor(Math.random()*18);
			var c = randomnumber/3;
				c = Math.floor(c);
			var r = randomnumber%3;
				r = Math.floor(r);
			var id = String(c*120) + String(r*104);
			var randomImg=Math.floor(Math.random()*5);
			
			$('.waitingList img:eq('+randomImg+')').clone().appendTo(".banner_theTeam").hide().css({ left: c*120, top: r*104, zIndex:zindex}).fadeIn(1000, function(){
				$('.waitingList img:eq('+randomImg+')').remove();
				$('.banner_theTeam img').each(function(){
					if ($(this).hasClass(id)){
						$(this).clone().appendTo('.waitingList').attr('class','');
						$(this).remove();
					}
				});
				$(this).attr('class','').addClass(id);				
			});
			teamI++;
		//}
	}
	
	zindex++;
	
	autoContinueReplace = setTimeout("randomReplace()",2000);
};

function randomInt(min, max) {
    return Math.round(min + Math.random()*(max-min));
}


function portOver(){
	$(this).find('rect').stop(true, true).animate({ 'stroke-width':"0" }, 75);
	$(this).find('.title_port').stop(true, true).animate({ color:'#ff0099'});
	$(this).find('.portDes').find('p').addClass('hover');
}
function portOut(){
	$(this).find('rect').stop(true, true).animate({ 'stroke-width':"16" }, 75);
	$(this).find('.title_port').stop(true, true).animate({ color:'#000000'});
	$(this).find('.portDes').find('p').removeClass('hover');
}


function call_initPort(){
	
	portLength = $('.list_port img').length;
	$('.list_port li').each(function(i){
		$(this).attr('id', 'portCanvas_'+i);	
	});
	
	initPort();
	
	
//	$('.list_port li').hover(
//		function(){
//			//$(this).find('.thumb_port').addClass('thumbPortDes').next().addClass('portDes_hover').animate({ backgroundPosition: '0 0'}, 200);
//			//$(this).find('img').stop(true, true).animate({ width: '236', height: '201', marginLeft: '-8', marginTop: '-8'}, 200);
//			//$(this).find('a.thumb_port').stop(true, true).animate({ 	borderLeftColor: '#ffffff', borderTopColor: '#ffffff', borderRightColor: '#ffffff', borderBottomColor: '#ffffff' }, 1000);
//			
//			$(this).find('rect').stop(true, true).animate({ 'stroke-width':"0" }, 100);
//			$(this).find('.title_port').stop(true, true).animate({ color:'#ff0099'});
//			
//			/*$(this).find('.thumb_port').find('span').hide();
//			$(this).find('.title_port').css({ color:'#ff0099'});*/
//		},
//		function(){
//			/*$(this).find('.portDes').stop(true, true).animate({ backgroundPosition: '236px 0'}, 200, function(){
//				$(this).css({ backgroundPosition: '-236px 0' }).prev().removeClass('thumbPortDes');
//			}).removeClass('portDes_hover');*/
//			//$(this).find('img').stop(true, true).animate({ width: '220', height: '185', marginLeft: '0', marginTop: '0'}, 200);
//			//$(this).find('a.thumb_port').stop(true, true).animate({ 	borderLeftColor: '#ededed', borderTopColor: '#ededed', borderRightColor: '#ededed', borderBottomColor: '#ededed' }, 1000);
//			
//			$(this).find('rect').stop(true, true).animate({ 'stroke-width':"16" }, 100);
//			$(this).find('.title_port').stop(true, true).animate({ color:'#000000'});
//			
//			/*$(this).find('.thumb_port').find('span').show();
//			$(this).find('.title_port').css({ color:'#000000'});*/
//		}		
//	);

	$('.list_port img').each(function(i){
		
		//for (var i=0; i<=getAllImg; i++){
			var getSrcImg = $('.list_port img:eq('+i+')').attr('src');			
			var Img = new Image();			
		
			Img.onerror = function(){
				//fn.error('This image cannot download!');
				return false;
			}		
			var src = getSrcImg;
			Img.onload = function(){ 
				//$('.loading').hide();
				var getSrcImg = $('.list_port .thumb_port:eq('+i+')').css({ backgroundImage:'none'});
				var getSrcImg = $('.list_port img:eq('+i+')').fadeIn();				
				//$('.portDes:eq('+i+')').animate({ marginTop:'0', opacity:'1'});
				
				Img.onload=function(){};
			}	
			Img.src = src;
		//}	
	});
}



function subscribe(subLink){
	$(subLink).hide().next().show(400);	
};




/****************************************************************************************************************/
/*								HOME BANNER 																	*/
/****************************************************************************************************************/

var ginSpeed		= 800;
var ginItemEach		= 1;
var ginCurrent		= 1;
var ginItemWidth	= 950;
var ginItemHeight	= 430;
var ginDelay 		= 5000;
var ginPause 		= false;
var ginToggle		= true;
var ginDotClicked	= false;
var ginAuto;
var ginSum;
var ginTransition	= "slide";	// slide fade
var ginEasing		= "easeOutQuint";
var ginItemClass 	= ".rotateCopy";
var ginNextClass 	= ".btn_next";
var ginPrevClass 	= ".btn_back";
var ginDotClass 	= ".port_dotlink";
var ginCoverClass	= ".port_slideshow";

function ginslider(){		
	
	// Count total item	
		ginSum=$(ginItemClass).length;
	
	//	Preload
		$('.port_view_all img').each(function(i){
			var getSrcImg = $('.port_view_all img:eq('+i+')').attr('src');			
			var Img = new Image();			
		
			Img.onerror = function(){
				//fn.error('This image cannot download!');
				return false;
			}		
			var src = getSrcImg;
			Img.onload = function(){ 
				//$('.loading').hide();
				 $('.port_view_all img:eq('+i+')').fadeIn();
				
				Img.onload=function(){};
			}	
			Img.src = src;
		});
		$('.port_view_all').css({
			width: ginItemWidth*ginSum
		});
	
	// Init dot navigation	
		ginslider_dot();	
	
	// Show first item
		//$('.rotateCopy').stop(true, true).fadeOut(ginSpeed);
		$(ginItemClass+':eq('+ginCurrent+')').stop(true, true).fadeIn(ginSpeed);	
	
	// Init items's position
		switch (ginTransition){
			case "slide":
				for(var i=0; i<ginSum ;i++){
					$(ginItemClass+':eq('+i+')').attr('rel',(i*(Number(ginItemWidth)))).css("left",(i*(Number(ginItemWidth))));
				}
				break;
			case "fade":
				for(var i=0; i<ginSum ;i++){
					$(ginItemClass).attr('rel',(i*(Number(ginItemWidth)))).css("left",0).hide();
					$(ginItemClass+':first').show();
				}
				break;
		}

	// Bind prev/next button
		$(ginNextClass).live("click", ginNext)/*.hover(
			function(){
				$(this).stop(true,true).animate({ backgroundPosition:'50% 45%'}, 300, ginEasing);
			},
			function(){
				$(this).stop(true,true).animate({ backgroundPosition:'0% 45%'}, 300, ginEasing, function(){
					$(this).css({ backgroundPosition:'100% 45%' })
				});
			}
		)*/;
		$(ginPrevClass).live("click", ginPrev)/*.hover(
			function(){
				$(this).stop(true,true).animate({ backgroundPosition:'50% 45%'}, 300, ginEasing);
			},
			function(){
				$(this).stop(true,true).animate({ backgroundPosition:'100% 45%'}, 300, ginEasing, function(){
					$(this).css({ backgroundPosition:'0% 45%' })					   
				});
			}
		)*/;

	// Set dimension of div cover
		$(ginCoverClass).width(Number(ginItemEach * (ginItemWidth)));
		//$(ginCoverClass).height(ginItemHeight);
	
	if ((ginSum>1) && (ginPause==false) && ( ginToggle==true)) 
		ginAuto=setTimeout("ginsliderPlay()",ginDelay);
}

function ginsliderPlay(){
	//clearTimeout(ginAuto);
	ginNext();
	clearTimeout(ginAuto);
	ginAuto=setTimeout("ginsliderPlay()",ginDelay);
}

function ginAutoNext(){
	//clearTimeout(ginAuto);
	//ginCurrent = ginCurrent+2;
	//if (ginCurrent>=ginSum) ginCurrent=0;
	//ginDotClicked = true;
	//$('#ft').text(ginCurrent+' / '+ ginSum);
	ginsliderPlay();
}

function ginNext(){
	//clearTimeout(ginAuto);
	//$(".btn_next").die("click", productNext);
	onSlide = true;	
	
	if (ginDotClicked == false){
		if(ginCurrent<(ginSum/ginItemEach)){
			
			//reset pagination
			$(ginDotClass+' img').removeClass('active');
			$(ginDotClass+' img:eq('+ginCurrent+')').addClass('active');	
			
			//$('.btn_prev a').show();
			
			switch (ginTransition){
				case "slide":
//					$(ginItemClass).stop(true,true).animate({left:'-='+(Number(ginItemWidth))*ginItemEach+'px'}, ginSpeed, ginEasing, function(){				
//						 onSlide = false;
//						//$(".btn_next").live("click", productNext);
//					});
					$('.port_view_all').stop(true,true).animate({left:'-='+(Number(ginItemWidth))*ginItemEach+'px'}, ginSpeed, ginEasing, function(){				
						 onSlide = false;
					});
					break;
				case "fade":
					$(ginItemClass).stop(true, true).fadeOut(ginSpeed);
					$(ginItemClass+':eq('+ginCurrent+')').stop(true, true).fadeIn(ginSpeed);	
					break;
			}
			
			ginCurrent++;
			
			//if (ginCurrent>=numItems/ginItemEach) $('.btn_next a').hide();			
			//$('#ft').text(ginCurrent+' / '+ ginSum);
		}
		else{
			
			switch (ginTransition){
				case "slide":
					//$(ginItemClass).stop(true,true).animate({left:'+='+(Number(ginItemWidth*(ginSum-1)))+'px' }, ginSpeed, ginEasing);
					$('.port_view_all').stop(true,true).animate({left:'+='+(Number(ginItemWidth*(ginSum-1)))+'px' }, ginSpeed, ginEasing);
					ginCurrent=1;
					break;
				case "fade":
					ginCurrent=0;
					$(ginItemClass).stop(true, true).fadeOut(ginSpeed);
					$(ginItemClass+':eq('+ginCurrent+')').stop(true, true).fadeIn(ginSpeed);	
					ginCurrent=1;
					break;
			}
					
			//reset pagination
			$(ginDotClass+' img').removeClass('active');
			$(ginDotClass+' img:eq(0)').addClass('active');	
			
			
			//$('#ft').text(ginCurrent+' / '+ ginSum);
		}
	}
	else{	
		alert(' not use for now ');
		//clearTimeout(ginAuto);
		var getTargetItem 	= ginCurrent;
		var getTargetItemW 	= getTargetItem*ginItemWidth;
		var getCurrentItem 	= (ginCurrent-1)*ginItemWidth;
		var gotoItem 		= getTargetItemW-getCurrentItem;
		var gotoAmount		= Math.abs(gotoItem);
		
		//$('#ft').text(ginCurrent +' / '+ getTargetItemW+' / '+ getCurrentItem +' / '+ gotoItem +' / '+ gotoAmount);
		
		if (gotoItem>0){
			$(ginItemClass).stop(true,true).animate({left:'-='+gotoAmount+'px' }, ginSpeed, ginEasing,
				function(){
					ginCurrent = getTargetItem+1;
					$('.disableLayer').hide();
					//if ((ginPause==false) && ( ginToggle==true)) ginAuto=setTimeout("ginAutoNext()",ginDelay);
					
					//$('#ft').text(ginCurrent+' / '+ getTargetItem);
				}
			);
		}
		else{
			$(ginItemClass).stop(true,true).animate({left:'+='+gotoAmount+'px' }, ginSpeed, ginEasing,
				function(){
					ginCurrent = getTargetItem+1;
					$('.disableLayer').hide();
					//if ((ginPause==false) && ( ginToggle==true)) ginAuto=setTimeout("ginAutoNext()",ginDelay);
					
					//$('#ft').text(ginCurrent+' / '+ getTargetItem);
				}
			);
		}
		
		ginDotClicked = false;
	}
	
	clearTimeout(ginAuto);
	if ((ginPause==false) && ( ginToggle==true)) ginAuto=setTimeout("ginsliderPlay()",ginDelay);
	return false;
}

function ginPrev(){
	clearTimeout(ginAuto);
	//$(".btn_prev").die("click", productPrev);
	onSlide = true;
	
	if(ginCurrent>1){	
				
		//$('.btn_next a').show();
		
		switch (ginTransition){
			case "slide":
//				$(ginItemClass).stop(true,true).animate({left:'+='+(Number(ginItemWidth))*ginItemEach+'px'}, ginSpeed, ginEasing, function(){			
//					 onSlide = false;
//					 //$(".btn_prev").live("click", productPrev);
//				});
				$('.port_view_all').stop(true,true).animate({left:'+='+(Number(ginItemWidth))*ginItemEach+'px'}, ginSpeed, ginEasing, function(){			
					 onSlide = false;
				});
				
				ginCurrent--;
				break;
			case "fade":
				ginCurrent--;
				$(ginItemClass).stop(true, true).fadeOut(ginSpeed);
				$(ginItemClass+':eq('+(ginCurrent-1)+')').stop(true, true).fadeIn(ginSpeed);	
				break;
		}
		
		
		//if (ginCurrent==1) $('.btn_prev a').hide();		
		
		//reset pagination
		var t_ginCurrent = ginCurrent-1;
		$(ginDotClass+' img').removeClass('active');
		$(ginDotClass+' img:eq('+t_ginCurrent+')').addClass('active');			
	}
	else{
		
		switch (ginTransition){
			case "slide":
				//$(ginItemClass).stop(true,true).animate({left:'-='+(Number(ginItemWidth*(ginSum-1)))+'px' }, ginSpeed, ginEasing);
				$('.port_view_all').stop(true,true).animate({left:'-='+(Number(ginItemWidth*(ginSum-1)))+'px' }, ginSpeed, ginEasing);				
				ginCurrent=ginSum;
				break;
			case "fade":
				ginCurrent=ginSum-1;
				$(ginItemClass).stop(true, true).fadeOut(ginSpeed);
				$(ginItemClass+':eq('+ginCurrent+')').stop(true, true).fadeIn(ginSpeed);
				ginCurrent=ginSum;
				break;
		}
		
		//reset pagination
		var t_numItems = ginSum-1;
		$(ginDotClass+' img').removeClass('active');
		$(ginDotClass+' img:eq('+t_numItems+')').addClass('active');	
		
		
	}
	
	clearTimeout(ginAuto);
	if ((ginPause==false) && ( ginToggle==true)) ginAuto=setTimeout("ginsliderPlay()",ginDelay);
	return false;
}

function ginslider_dot(){	/* generate pagination */
	if (ginSum>1){
		for (var tempPaging=0; tempPaging<ginSum; tempPaging++){
			$(ginDotClass).append('<img src="'+siteUrl+'images/b.gif" alt="'+tempPaging+'" width="15" height="15" />');
		}
		
		$(ginDotClass+' img:first').addClass('active');		
		$(ginDotClass+' img').click(function(){
			
			$(ginDotClass+' img').removeClass('active');
			$(this).addClass('active');
			$('.disableLayer').show();
			//clearTimeout(ginAuto);
			
			switch (ginTransition){
				case "slide":
					var getTargetItem 	= Number($(this).attr('alt'));
					var getTargetItemW 	= getTargetItem*ginItemWidth;
					var getCurrentItem 	= $(ginItemClass+':eq('+ Number(ginCurrent-1) +')').attr('rel');
					var gotoItem 		= getTargetItemW-getCurrentItem;
					var gotoAmount		= Math.abs(gotoItem);
					
					if (gotoItem>0){
						//$(ginItemClass).stop(true,true).animate({left:'-='+gotoAmount+'px' }, ginSpeed, ginEasing,
						$('.port_view_all').stop(true,true).animate({left:'-='+gotoAmount+'px' }, ginSpeed, ginEasing,  
							function(){
								ginCurrent = getTargetItem+1;
								$('.disableLayer').hide();
								
								//if ((ginPause==false) && ( ginToggle==true)) setTimeout("ginAutoNext()",ginDelay);					
								//$('#ft').text(ginCurrent+' / '+ getTargetItem);
							}
						);
					}
					else{
						//$(ginItemClass).stop(true,true).animate({left:'+='+gotoAmount+'px' }, ginSpeed, ginEasing,
					  $('.port_view_all').stop(true,true).animate({left:'+='+gotoAmount+'px' }, ginSpeed, ginEasing,  
							function(){
								ginCurrent = getTargetItem+1;
								$('.disableLayer').hide();
								
								//if ((ginPause==false) && ( ginToggle==true)) setTimeout("ginAutoNext()",ginDelay);						
								//$('#ft').text(ginCurrent+' / '+ getTargetItem);
							}
						);
					}
					clearTimeout(ginAuto);
					if ((ginPause==false) && ( ginToggle==true)) ginAuto=setTimeout("ginAutoNext()",ginDelay);
					break;
					
				case "fade":
					clearTimeout(ginAuto);
					ginCurrent = Number($(this).attr('alt'));
					if ((ginPause==false) && ( ginToggle==true)) ginAuto=setTimeout("ginAutoNext()",0);
					$('.disableLayer').hide();
					break;
			}			
			
		});
	}
};





/****************************************************************************************************************/
/*								PORTFOLIO																		*/
/****************************************************************************************************************/

/*$(window).scroll(function(){				
	$("#viewmoreloading").remove();	
	clearTimeout(timeout);
	timeout = setTimeout(function() {							
		if($("#loadcontinues").length>0 && page<=numPage ){					
			var url_load = $("#loadcontinues").val();									
			if ($(document).scrollTop() >= $(document).height() - $(window).height()-100){						
			   loadportfolio(url_load);
			   url_load = "";					   
			}					
		}										
	}, 150);						
}); */
function portfolio_scrollLoad(){
	$(window).scroll(function(){	
		var seconds = 6;	
		var url_load = $("#loadcontinues").val();
		var interv = setInterval(function()
		{
			//alert("Top: "+$(document).scrollTop()+" - Bottom: "+($(document).height() - $(window).height()));
			//if(seconds == 0 && ($(document).scrollTop()+200) >= $(document).height() - $(window).height())
			if (seconds == 0 && $(window).scrollTop() + $(window).height()*2 >= $(document).height())
			{
				clearInterval(interv);
				loadportfolio(url_load);				
				url_load = "";		
			}
			else
			{
				seconds--;					
			}
		}, 
		100);
	});
}


var portLength;
var portFadeSpeed = 50;
var portInitNum=0;
var portInitFade;
var paper;
function initPort(){
		paper = Raphael("portCanvas_"+portInitNum+"", 236, 201);
		paper.clear();
		paper.rect(118, 100, 1, 1, 0).attr({fill: "#cfcfcf", stroke:"none"}).animate({fill: "#ededed", width:"237", height:"201", x:"0", y:"0" }, 200);
			//paper.rect(118, 100, 1, 1, 0).attr({fill: "#cecece"}).animate({fill: "#ededed", "stroke-width": 235, stroke:"#ededed", width:"236", height:"201"}, 2000);
	portInitNum=Number(portInitNum)+1;
	
	if (portInitNum<portLength) portInitFade=setTimeout("initPort("+portInitNum+")", portFadeSpeed);
	else{
		clearTimeout(portInitFade);	
		setTimeout("$('.thumb_port').show().css({display:'block'})",200);
		loadPort();
	}
};


function loadPort(){
	$('.list_port img').each(function(i){
		
	//for (var i=0; i<=getAllImg; i++){
		var getSrcImg = $('.list_port img:eq('+i+')').attr('src');			
		var Img = new Image();			
	
		Img.onerror = function(){
			//fn.error('This image cannot download!');
			return false;
		}		
		var src = getSrcImg;
		Img.onload = function(){ 
			//$('.loading').hide();
			var getSrcImg = $('.list_port .thumb_port:eq('+i+')').css({ backgroundImage:'none'});			
			//$('.portDes:eq('+i+')').animate({ bottom:'0', opacity:'1'});
			
			var getSrcImg = $('.list_port img:eq('+i+')').fadeIn(500, function(){
				$('#list_port_items svg').css({ zIndex:'9'}).find('rect').attr({ fill: "none", 'stroke-width':"0", stroke:"#ededed" }).animate({ 'stroke-width':"16" }, 100);
			});
			var getSrcImg = $('.list_port img:eq('+i+')').fadeIn(500);
			
			if ($.browser.msie){
				$('.thumb_port span').show().css({display:'block'});
			}
			
			Img.onload=function(){};
		}	
		Img.src = src;
	//}	
	});
};


function hoverPort(){
	
};




// ********************************* //
// Contact Google Map

var map; 
var markers = [];
var marker;
var zoom = 17;
var infoWindow;    
function initialize() {		
	var latlng = new google.maps.LatLng(10.785584719425003,106.69042136441806);		
	//var latlng = new google.maps.LatLng(10.759870804483496,106.66239738464355);		
	var options = {
	 zoom: zoom,
	 center: latlng,
	 mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	map = new google.maps.Map(document.getElementById("map"), options);		
	placeMarker(latlng, null,null);
	infoWindow = new google.maps.InfoWindow({size: new google.maps.Size(200,150)});										
}

function showAddress(obj) {
	 if (typeof obj == "object") {
	   $('.contactMap').animate({ width:'395'}, 500, function(){		
			var address =  $(obj).attr("rel");				
			var possition = searchLocations(address);
			$("a.btn").removeClass("active");
			$(obj).addClass("active");			
		});
	 }
	 else
	 {
		 $('.contactMap').animate({ width:'395'}, 500, function(){		
			var address =  obj;			
			var possition = searchLocations(address);					
		});
	 }
}

function searchLocations(address) {		 	
	 var geocoder = new google.maps.Geocoder();
	 geocoder.geocode({address: address}, function(results, status) {
	   if (status == google.maps.GeocoderStatus.OK) {
			placeMarker(results[0].geometry.location, null, address);			
			return results[0].geometry.location;
	   } else {			   	
		  return null;
	   }
	 });
 }
function placeMarker(location, obj, address) 
{	
	clearMarkers();			
	var image = siteUrl +"template/Default/images/contact_logo.png";	  
	marker = new google.maps.Marker({
		  position: location, 
		  map: map,	
		  icon:image,
		  clickable: false,
		  draggable:false
	  });
   google.maps.event.addListener(marker, 'click', function() {
	infoWindow.setContent(address);
	infoWindow.open(map, marker);
  });
  google.maps.event.addListener(marker, 'dragend', function() {			  
			alert(marker.getPosition().lat()+","+marker.getPosition().lng());
	});
  markers.push(marker);
  map.setZoom(zoom);  
  map.setCenter(location);
}	
function clearMarkers() 
{
	 for (var i = 0; i < markers.length; i++) {
	   markers[i].setMap(null);
	 }
	 markers.length = 0;
}




function getDocumentSize(val){
	var xScroll,yScroll,value;
	
	if(window.innerHeight&&window.scrollMaxY){
		xScroll=window.innerWidth+window.scrollMaxX;
		yScroll=window.innerHeight+window.scrollMaxY;
	}
	else if(document.body.scrollHeight>document.body.offsetHeight){
		xScroll=document.body.scrollWidth;
		yScroll=document.body.scrollHeight;
		}
		else{
			xScroll=document.body.offsetWidth;
			yScroll=document.body.offsetHeight;
		}
	
	var windowWidth,windowHeight;
	
	if(self.innerHeight){
		if(document.documentElement.clientWidth){
			windowWidth=document.documentElement.clientWidth;
		}
		else{
			windowWidth=self.innerWidth;
		}
		windowHeight=self.innerHeight;
	}
	else if(document.documentElement&&document.documentElement.clientHeight){
			windowWidth=document.documentElement.clientWidth;
			windowHeight=document.documentElement.clientHeight;
		}
		else if(document.body){
			windowWidth=document.body.clientWidth;
			windowHeight=document.body.clientHeight;
		}
	
	if(yScroll<windowHeight){
		pageHeight=windowHeight;
	}
	else{
		pageHeight=yScroll
	}
	
	if(xScroll<windowWidth){
		pageWidth=xScroll
	}
	else{
		pageWidth=windowWidth
	}
	
	arrayPageSize=new Array(pageWidth, pageHeight, windowWidth, windowHeight);
	return arrayPageSize[val];
};




































/* Copyright (c) 2006 Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 * Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
 * Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
 *
 * $LastChangedDate: 2007-12-20 09:02:08 -0600 (Thu, 20 Dec 2007) $
 * $Rev: 4265 $
 *
 * Version: 3.0
 * 
 * Requires: $ 1.2.2+
 */

(function($) {

$.event.special.mousewheel = {
	setup: function() {
		var handler = $.event.special.mousewheel.handler;
		
		// Fix pageX, pageY, clientX and clientY for mozilla
		if ( $.browser.mozilla )
			$(this).bind('mousemove.mousewheel', function(event) {
				$.data(this, 'mwcursorposdata', {
					pageX: event.pageX,
					pageY: event.pageY,
					clientX: event.clientX,
					clientY: event.clientY
				});
			});
	
		if ( this.addEventListener )
			this.addEventListener( ($.browser.mozilla ? 'DOMMouseScroll' : 'mousewheel'), handler, false);
		else
			this.onmousewheel = handler;
	},
	
	teardown: function() {
		var handler = $.event.special.mousewheel.handler;
		
		$(this).unbind('mousemove.mousewheel');
		
		if ( this.removeEventListener )
			this.removeEventListener( ($.browser.mozilla ? 'DOMMouseScroll' : 'mousewheel'), handler, false);
		else
			this.onmousewheel = function(){};
		
		$.removeData(this, 'mwcursorposdata');
	},
	
	handler: function(event) {
		var args = Array.prototype.slice.call( arguments, 1 );
		
		event = $.event.fix(event || window.event);
		// Get correct pageX, pageY, clientX and clientY for mozilla
		$.extend( event, $.data(this, 'mwcursorposdata') || {} );
		var delta = 0, returnValue = true;
		
		if ( event.wheelDelta ) delta = event.wheelDelta/120;
		if ( event.detail     ) delta = -event.detail/3;
//		if ( $.browser.opera  ) delta = -event.wheelDelta;
		
		event.data  = event.data || {};
		event.type  = "mousewheel";
		
		// Add delta to the front of the arguments
		args.unshift(delta);
		// Add event to the front of the arguments
		args.unshift(event);

		return $.event.handle.apply(this, args);
	}
};

$.fn.extend({
	mousewheel: function(fn) {
		return fn ? this.bind("mousewheel", fn) : this.trigger("mousewheel");
	},
	
	unmousewheel: function(fn) {
		return this.unbind("mousewheel", fn);
	}
});

})(jQuery);







var _jscr_originalSizes = new Array();
var _jscr_differenceSizes = new Array();
var _jscr_previousWindowSize = new Array();
var _jscr_originalPercentages = new Array();
var _jscr_intervals = new Array();
var _jscr_trackInt = new Array();
var _jscr_originalPos = new Array();
var _jscr_globalProperties = new Array();

jQuery.jScrollHorizontalPane = {
	active : []
};

jQuery.fn.jScrollHorizontalPane = function(settings)
{
	settings = jQuery.extend(
		{
			scrollbarHeight : 10,
			scrollbarMargin : 5,
			wheelSpeed : 18,
			showArrows : false,
			arrowSize : 10,
			animateTo : false,
			dragMinWidth : 1,
			dragMaxWidth : 99999,
			animateInterval : 100,
			animateStep: 3,
			maintainPosition: true, 
			resize: true,
			minimumWidth: 200,
			reset: false
		}, settings
	);
	
	return this.each(
		function()
		{
			if(settings.reset == true) {
				jQuery.fn.jScrollHorizontalPane.reset();
			}
			
			//This holds each one of the intervals, defaulting with one at the beginning.
			var $this = jQuery(this);			
			var mouseWheelNext = 0;
			var mouseWheelMove = false;
			var currentId = $this.attr('id');
			
			if(currentId == undefined) {
				currentId = $this.attr('class');
			}
			
			var previousWindow = _jscr_previousWindowSize[currentId];
			_jscr_originalPos[currentId] = -1;
			_jscr_globalProperties[currentId] = settings;
			_jscr_previousWindowSize[currentId] = $(window).width();

			//On initial load, set values needed for percentage resizing.
			if(_jscr_originalSizes[currentId] == undefined) {		

				//ie6 hack, since jquery width doesnt get the right value on an inproper refresh
				if((jQuery.browser.msie) && (parseInt(jQuery.browser.version) == 6)) {
					var outerWidth = parseInt($this.outerWidth()) - parseInt($this.offset().left);
					_jscr_differenceSizes[currentId] = $this.offset().left / $(window).width();
				} else {
					var outerWidth = $this.outerWidth();
					_jscr_differenceSizes[currentId] = $this.position().left / $(window).width();
				}

				percentageWidth = (outerWidth / $(window).width());			
				_jscr_originalPercentages[currentId] = percentageWidth;
				_jscr_originalSizes[currentId] = $(window).width();
			} else { 
				percentageWidth = _jscr_originalPercentages[currentId];
				diff = _jscr_differenceSizes[currentId] - (($this.offset().left + _jscr_originalPos[currentId])/ $(window).width());
				percentageWidth = percentageWidth + diff;
			}

			var halfIntervals = new Array();
			_jscr_intervals = new Array();
			halfIntervals[0] = 0;
			_jscr_intervals[0] = 0;
			margin = $this.position().left;
			offset = 1;
			
			if(margin < 0) {
				margin = 0;
			}
			
			//Handles interval code
			$(".scroll-interval", $this).each(
				function(i, elem) {
					pos = $(elem).position().left - margin;
					if(pos != 0) {
						_jscr_intervals[i+offset] = pos;
					} else { 
						offset--;
					}
				}
			);
				
			if(_jscr_intervals.length <= 1) { 
				_jscr_intervals = new Array();
			}

			if (jQuery(this).parent().is('.jScrollPaneContainer')) {
				var currentScrollPosition = settings.maintainPosition ? $this.offset({relativeTo:jQuery(this).parent()[0]}).left : 0;
				var $c = jQuery(this).parent();
				var paneWidth = $c.outerWidth();
				var paneHeight = $c.innerHeight();
				var rightPos = $this.offset().left + _jscr_originalPos[currentId] + paneWidth;
				
				if((previousWindow != $(window).width()) && ((rightPos > $(window).width()) || (previousWindow < $(window).width())) && (settings.resize == true)) {

					if($(window).width() >= _jscr_originalSizes[currentId]) {
						paneWidth = ($(window).width() *  percentageWidth);
					} else {
						//Give the outside edge a 10 px buffer margin
						paneWidth = $(window).width() - ($this.offset().left + _jscr_originalPos[currentId]) - 10;
					}

					if(paneWidth < settings.minimumWidth){
						paneWidth = settings.minimumWidth;
					}

					jQuery(this).parent().css(
									{ 
										'height':paneHeight+'px', 
										'width': paneWidth + 'px'
									}
								);
				}
				
				var trackWidth = paneWidth;

				if($c.unmousewheel) {
						
					if($.browser.opera) {
						$c.unbind("mousewheel", fn = function() { });	
					} else {
						$c.unmousewheel();
					}				
				}

				jQuery('>.jScrollPaneTrack, >.jScrollArrowLeft, >.jScrollArrowRight', $c).remove();
				$this.css({'left':0});
				_jscr_originalPos[currentId] = -1;
			} else {
				var currentScrollPosition = 0;
				this.originalPadding = $this.css('paddingTop') + ' ' + $this.css('paddingRight') + ' ' + $this.css('paddingBottom') + ' ' + $this.css('paddingLeft');
				this.originalSidePaddingTotal = (parseInt($this.css('paddingLeft')) || 0) + (parseInt($this.css('paddingRight')) || 0);
				var paneWidth = $this.outerWidth();
				var rightPos = $this.offset().left + _jscr_originalPos[currentId] + paneWidth;

				if((rightPos) > $(window).width()) { 
					paneWidth = $(window).width() *  percentageWidth; 
				}
				
				if(paneWidth < settings.minimumWidth){
					paneWidth = settings.minimumWidth;
				}
					
				var paneHeight = $this.innerHeight();
				var trackWidth = paneWidth;
				
				$this.wrap(
					jQuery('<div></div>').attr(
						{'className':'jScrollPaneContainer'}
					).css(
						{
							'height':paneHeight+'px', 
							'width':paneWidth+'px'
						}
					)
				);
				// deal with text size changes (if the jquery.em plugin is included)
				// and re-initialise the scrollPane so the track maintains the
				// correct size
				jQuery(document).bind(
					'emchange', 
					function(e, cur, prev)
					{
						$this.jScrollHorizontalPane(settings);
					}
				);
			}
			var p = this.originalSidePaddingTotal;
			
			$this.css(
				{
					'height': paneHeight - settings.scrollbarHeight - p + 'px',
					'width': 'auto',
					'paddingRight':settings.scrollbarMargin + 'px'
				}
			);

			var contentWidth = $this.outerWidth();

			//ie6 and 7, outside width does not always guarantee the full size of the div
			//is returned for outerWidth
			if($.browser.msie || $.browser.opera || $.browser.safari) {
				var ieWidth = 0;
				$this.children().each(function(i, elem) { if($(elem).outerWidth() > ieWidth) { ieWidth = $(elem).outerWidth();}});
				if(ieWidth > contentWidth) {
					contentWidth = ieWidth;
				}				
			}

			var percentInView = paneWidth / contentWidth;
			var trackIntervals = new Array();

			if (percentInView < 0.99) {
				var $container = $this.parent();

				$container.append(
					jQuery('<div></div>').attr({'className':'jScrollPaneTrack'}).css({'height':settings.scrollbarHeight+'px'}).append(
						jQuery('<div></div>').attr({'className':'jScrollPaneDrag'}).css({'height':settings.scrollbarHeight+'px'}).append(
							jQuery('<div></div>').attr({'className':'jScrollPaneDragLeft'}).css({'height':settings.scrollbarHeight+'px'}),
							jQuery('<div></div>').attr({'className':'jScrollPaneDragRight'}).css({'height':settings.scrollbarHeight+'px'})
						)
					)
				);
				
				var $track = jQuery('>.jScrollPaneTrack', $container);
			
				//Attach the intervals to the track
				for(inter in _jscr_intervals) { 
					
					if(settings.showArrows == true) { 
						scrollOffset = settings.arrowSize;
					} else { 
						scrollOffset = 0;
					}

					intervalTrackPos = _jscr_intervals[inter] / contentWidth * $track.width() - (scrollOffset);
					trackIntervals[inter] = intervalTrackPos;
					
					if(trackIntervals[inter - 1] != undefined) {
						halfIntervals[inter-1] = (trackIntervals[inter] + trackIntervals[inter-1]) / 2;
					}
				
					if(inter != 0) { 
						interObj = jQuery('<div>|</div>').attr({'className':'jScrollIntervalTrack'}).css({'left':intervalTrackPos + 'px'})
						$track.append(interObj);
					}
				}

				var $drag = jQuery('>.jScrollPaneTrack .jScrollPaneDrag', $container);
				
				if (settings.showArrows) {
					
					var currentArrowButton;
					var currentArrowDirection;
					var currentArrowInterval;
					var currentArrowInc;
					var whileArrowButtonDown = function()
					{
						if (currentArrowInc > 4 || currentArrowInc%4==0) {
							positionDrag(dragPosition + currentArrowDirection * mouseWheelMultiplier);
						}
						currentArrowInc ++;
					};
					var onArrowMouseUp = function(event)
					{
						jQuery('body').unbind('mouseup', onArrowMouseUp);
						currentArrowButton.removeClass('jScrollActiveArrowButton');
						clearInterval(currentArrowInterval);
						arrowUp = true;
						moveIntervals();
					};
					var onArrowMouseDown = function() {
						jQuery('body').bind('mouseup', onArrowMouseUp);
						currentArrowButton.addClass('jScrollActiveArrowButton');
						currentArrowInc = 0;
						whileArrowButtonDown();
						currentArrowInterval = setInterval(whileArrowButtonDown, 100);
					};
					$container
						.append(
							jQuery('<a></a>')
								.attr({'href':'javascript:;', 'className':'jScrollArrowLeft'})
								.css({'width':settings.arrowSize+'px'})
								.html('Scroll Left')
								.bind('mousedown', function()
								{
									currentArrowButton = jQuery(this);
									currentArrowDirection = -1;
									onArrowMouseDown();
									this.blur();
									return false;
								}),
							jQuery('<a></a>')
								.attr({'href':'javascript:;', 'className':'jScrollArrowRight'})
								.css({'width':settings.arrowSize+'px'})
								.html('Scroll Right')
								.bind('mousedown', function()
								{
									currentArrowButton = jQuery(this);
									currentArrowDirection = 1;
									onArrowMouseDown();
									this.blur();
									return false;
								})
						);
					if (settings.arrowSize) {
						trackWidth = paneWidth - settings.arrowSize - settings.arrowSize;
						$track
							.css({'width': trackWidth+'px', left:settings.arrowSize+'px'})
					} else {
						var leftArrowWidth = jQuery('>.jScrollArrowLeft', $container).width();
						settings.arrowSize = leftArrowWidth;
						trackWidth = paneWidth - leftArrowWidth - jQuery('>.jScrollArrowRight', $container).width();
						$track
							.css({'width': trackWidth +'px', left: leftArrowWidth+'px'})
					}
				}
				
				var $pane = jQuery(this).css({'position':'absolute', 'overflow':'visible'});
				
				var currentOffset;
				var maxX;
				var mouseWheelMultiplier;
				
				// store this in a seperate variable so we can keep track more accurately than just updating the css property..
				var dragPosition = 0;
				var dragMiddle = percentInView*paneWidth/2;
				
				// pos function borrowed from tooltip plugin and adapted...
				var getPos = function (event, c) {
					var p = c == 'X' ? 'Left' : 'Bottom';
					return event['page' + c] || (event['client' + c] + (document.documentElement['scroll' + p] || document.body['scroll' + p])) || 0;
				};
				
				var ignoreNativeDrag = function() {	return false; };
				var currentInterval = 0;
				var direction = 1;
				var arrowUp = false;
				var intervalMove = false;
				_jscr_trackInt[currentId] = -1;;
						
				var initDrag = function()
				{
					ceaseAnimation();
					currentOffset = $drag.offset(false);
					currentOffset.left -= dragPosition;
					maxX = trackWidth - $drag[0].offsetWidth;
					mouseWheelMultiplier = 2 * settings.wheelSpeed * maxX / contentWidth;
				};
				
				var onStartDrag = function(event)
				{
					initDrag();
					dragMiddle = getPos(event, 'X') - dragPosition - currentOffset.left;
					jQuery('body').bind('mouseup', onStopDrag).bind('mousemove', updateScroll);
					if (jQuery.browser.msie) {
						jQuery('body').bind('dragstart', ignoreNativeDrag).bind('selectstart', ignoreNativeDrag);
					}
					return false;
				};
				var onStopDrag = function()
				{
					jQuery('body').unbind('mouseup', onStopDrag).unbind('mousemove', updateScroll);
					dragMiddle = percentInView*paneWidth/2;
					moveIntervals();
					
					if (jQuery.browser.msie) {
						jQuery('body').unbind('dragstart', ignoreNativeDrag).unbind('selectstart', ignoreNativeDrag);
					}
				};
				var positionDrag = function(destX)
				{
					//Figure out if we need to adjust because of intervals.
					evaluateIntervals(dragPosition, destX);
					destX = destX < 0 ? 0 : (destX > maxX ? maxX : destX);
					dragPosition = destX;

					$drag.css({'left':destX +'px'});
					var p = destX / maxX;
					_jscr_originalPos[currentId] = (paneWidth-contentWidth) * p * -1;
					//$pane.css({'left':((paneWidth-contentWidth)*p) + 'px'});
					$pane.stop(true,true).animate({'left':((paneWidth-contentWidth)*p)}, 1000, 'easeOutQuart');
					$this.trigger('scroll');
				};
				
				var updateScroll = function(e)
				{
					positionDrag(getPos(e, 'X') - currentOffset.left - dragMiddle);
				};
				
				var evaluateIntervals = function(position, destX) { 
	
					if((intervalMove == false) && (mouseWheelMove != true)) { 
							_jscr_trackInt[currentId] = -1;
							halfInter = -1;
							
							smallInter = -1;
							bigInter = -1;
							
							endDragPos = destX + $drag.width();
							fullTrackWidth = $('.jScrollPaneTrack').width();

							for(inter in trackIntervals) { 
								if((endDragPos >= fullTrackWidth) && (endDragPos >= trackIntervals[inter])) {
									_jscr_trackInt[currentId] = inter;
								} else if(destX >= trackIntervals[inter]) {
									smallInter = inter;
								}	else { 
									bigInter = inter;
									break;
								}
								
							}

							if(_jscr_trackInt[currentId] == -1) {
								smallDistance = destX - trackIntervals[smallInter];
								largeDistance = trackIntervals[bigInter] - destX;
								
								if(smallDistance <= largeDistance) {
									_jscr_trackInt[currentId] = smallInter;
								} else { 
									_jscr_trackInt[currentId] = bigInter;
								}
							}
					} else { 
						intervalMove = false;
					}
	
				}
				
				var moveIntervals = function() { 
					if(_jscr_trackInt[currentId] != -1) { 
						//Catching arrow clicks
						if(arrowUp == true) { 
							if((direction == -1) && (_jscr_trackInt[currentId] != 0)) { 
								_jscr_trackInt[currentId] = currentInterval - 1;
							} else if((direction == 1) && (_jscr_trackInt[currentId] != (_jscr_intervals.length -1))) {
								_jscr_trackInt[currentId] = parseInt(currentInterval) + 1;
							}
							arrowUp = false;
						} 
						
						intervalMove = true;
						positionDrag(trackIntervals[_jscr_trackInt[currentId]]);
						currentInterval = _jscr_trackInt[currentId];
					}
				}
				
				var arrowSize = 0;
				
				if(settings.showArrows == true) {
					arrowSize = settings.arrowSize;
				} 
				
				var dragH = Math.max(Math.min(percentInView*(paneWidth-arrowSize*2), settings.dragMaxWidth), settings.dragMinWidth);
				
				$drag.css(
					{'width':dragH+'px'}
				).bind('mousedown', onStartDrag);
				
				var trackScrollInterval;
				var trackScrollInc;
				var trackScrollMousePos;
				var doTrackScroll = function()
				{
					if (trackScrollInc > 8 || trackScrollInc%4==0) {
						positionDrag((dragPosition - ((dragPosition - trackScrollMousePos) / 2)));
					}
					trackScrollInc ++;
				};
				var onStopTrackClick = function()
				{
					clearInterval(trackScrollInterval);
					moveIntervals();
					jQuery('body').unbind('mouseup', onStopTrackClick).unbind('mousemove', onTrackMouseMove);
				};
				var onTrackMouseMove = function(event)
				{
					trackScrollMousePos = getPos(event, 'X') - currentOffset.left - dragMiddle;
				};
				var onTrackClick = function(event)
				{
					initDrag();
					onTrackMouseMove(event);
					trackScrollInc = 0;
					jQuery('body').bind('mouseup', onStopTrackClick).bind('mousemove', onTrackMouseMove);
					trackScrollInterval = setInterval(doTrackScroll, 100);
					doTrackScroll();
				};
				
				$track.bind('mousedown', onTrackClick);
				
				// if the mousewheel plugin has been included then also react to the mousewheel
				if ($container.mousewheel) {

					$container.mousewheel (
						function (event, delta) {
							var movePos = -1;
							
							if($.browser.opera) {
								delta = event.wheelDelta / 120;	
							}

							//The following handles intervals with the mouse wheel
							if(trackIntervals.length > 1) {
								mouseWheelMove = true;
										
								//increase or decrease the interval we are currently on, depending
								//on the direction of the mouse wheel
								if(delta < 0) {
									_jscr_trackInt[currentId] = parseInt(_jscr_trackInt[currentId]) + 1;

									if((_jscr_trackInt[currentId]) >= trackIntervals.length - 1) {
										_jscr_trackInt[currentId] = trackIntervals.length - 1;
									}
									
									//If the next interval is beyond the dragWidth then recalculate.
									if((parseInt($drag.width())+ parseInt(trackIntervals[_jscr_trackInt[currentId]])) > parseInt($('.jScrollPaneTrack').width())) {
										movePos = parseInt($('.jScrollPaneTrack').width()) - $drag.width();
									}
									
								} else { 
									_jscr_trackInt[currentId] = parseInt(_jscr_trackInt[currentId]) - 1;
									if(_jscr_trackInt[currentId] < 0) {
										_jscr_trackInt[currentId] = 0;
									}
								}
							}

							initDrag();
							ceaseAnimation();
							var d = dragPosition;
							
							//when intervals are in use, mouseWheelMove is set to true
							if(mouseWheelMove == true) {
								if(movePos == -1) {
									positionDrag(trackIntervals[_jscr_trackInt[currentId]]);
								} else {
									positionDrag(movePos);
								}
							} else {
								positionDrag(dragPosition - delta * mouseWheelMultiplier);
							}
							
							moveIntervals();
							var dragOccured = d != dragPosition;
							mouseWheelMove = false;
							return !dragOccured;
						},
						false
					);					
				}
				var _animateToPosition;
				var _animateToInterval;
				function animateToPosition()
				{

					var diff = (_animateToPosition - dragPosition) / settings.animateStep;
					
					if ((diff > 1 || diff < -1) && ((dragPosition + diff + $drag.width()) < (paneWidth))) {
						positionDrag(dragPosition + diff);
					} else {
						positionDrag(_animateToPosition);
						ceaseAnimation();
					}
				}
				var ceaseAnimation = function()
				{
					if (_animateToInterval) {
						clearInterval(_animateToInterval);
						delete _animateToPosition;
					}
				};
				var scrollTo = function(pos, preventAni)
				{
					if (typeof pos == "string") {
						$e = jQuery(pos, this);

						if (!$e.length) return;
						pos = $e.position().left;
					}

					ceaseAnimation();
					var destDragPosition = -pos/(paneWidth-contentWidth) * maxX;
					if (!preventAni || settings.animateTo) {
						_animateToPosition = destDragPosition;
						_animateToInterval = setInterval(animateToPosition, settings.animateInterval);
		
					} else {
						positionDrag(destDragPosition);
					}	
				};
				$this[0].scrollTo = scrollTo;
				
				$this[0].scrollBy = function(delta)
				{
					var currentPos = -parseInt($pane.css('left')) || 0;
					scrollTo(currentPos + delta);
				};
				
				initDrag();
				
				scrollTo(-currentScrollPosition, true);
				
				jQuery.jScrollHorizontalPane.active.push($this[0]);

			} else {
				var scrollTo = function(pos, preventAni) {}
				$this[0].scrollTo = scrollTo;
				
				$this.css(
					{
						'height':paneHeight-this.originalSidePaddingTotal+'px',
						'width': paneWidth+'px',
						'padding':this.originalPadding
					}
				);
				// remove from active list?
			}
			
		}
	)
};

jQuery.fn.jScrollHorizontalPane.reset = function() {
	_jscr_originalSizes = new Array();
	_jscr_differenceSizes = new Array();
	_jscr_previousWindowSize = new Array();
	_jscr_originalPercentages = new Array();
	_jscr_intervals = new Array();
	_jscr_trackInt = new Array();
	_jscr_originalPos = new Array();
	_jscr_globalProperties = new Array();
}

// clean up the scrollTo expandos
jQuery(window)
	.bind('unload', function() {
		var els = jQuery.jScrollHorizontalPane.active; 
		for (var i=0; i<els.length; i++) {
			els[i].scrollTo = els[i].scrollBy = null;
		}
	}
);
	
 
( function( $ )  
{ 
 
	jQuery(function($) {
		$( window ).wresize(resizeScroller);
		
		function resizeScroller() {
		$('.scroll-pane').each(function(i, elem) { 	
			
			if($(elem).attr('id') == undefined) {
				id = $(elem).attr('class');
			} else {
				id = $(elem).attr('id');
			}
			$(elem).jScrollHorizontalPane(_jscr_globalProperties[$(elem).attr('id')]);
		});
		}	
	});


    $.fn.wresize = function( f )  
    { 
        version = '1.1'; 
        wresize = {fired: false, width: 0}; 
 
        function resizeOnce()  
        { 
            if ( $.browser.msie ) 
            { 
                if ( ! wresize.fired ) 
                { 
                    wresize.fired = true; 
                } 
                else  
                { 
                    var version = parseInt( $.browser.version, 10 ); 
                    wresize.fired = false; 
                    if ( version < 7 ) 
                    { 
                        return false; 
                    } 
                    else if ( version == 7 ) 
                    { 
                        //a vertical resize is fired once, an horizontal resize twice 
                        var width = $( window ).width(); 
                        if ( width != wresize.width ) 
                        { 
                            wresize.width = width; 
                            return false; 
                        } 
                    } 
                } 
            }
 
            return true; 
        } 
 
        function handleWResize( e )  
        { 
			if ( resizeOnce() ) 
            { 
                return f.apply(this, [e]); 
            } 
        } 
 
        this.each( function()  
        { 
            if ( this == window ) 
            { 
                $( this ).resize( handleWResize ); 
            } 
            else 
            { 
                $( this ).resize( f ); 
            } 
        } ); 
 
        return this; 
    }; 
 
} ) ( jQuery );





















/*
 * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
 *
 * Uses the built in easing capabilities added In jQuery 1.1
 * to offer multiple easing options
 *
 * TERMS OF USE - jQuery Easing
 * 
 * Open source under the BSD License. 
 * 
 * Copyright © 2008 George McGinley Smith
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this list of 
 * conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list 
 * of conditions and the following disclaimer in the documentation and/or other materials 
 * provided with the distribution.
 * 
 * Neither the name of the author nor the names of contributors may be used to endorse 
 * or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE. 
 *
*/

// t: current time, b: begInnIng value, c: change In value, d: duration
jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		//alert(jQuery.easing.default);
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeInOutQuad: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t + b;
		return -c/2 * ((--t)*(t-2) - 1) + b;
	},
	easeInCubic: function (x, t, b, c, d) {
		return c*(t/=d)*t*t + b;
	},
	easeOutCubic: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t + 1) + b;
	},
	easeInOutCubic: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;
	},
	easeInQuart: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t + b;
	},
	easeOutQuart: function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	},
	easeInOutQuart: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
		return -c/2 * ((t-=2)*t*t*t - 2) + b;
	},
	easeInQuint: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t*t + b;
	},
	easeOutQuint: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t*t*t + 1) + b;
	},
	easeInOutQuint: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
		return c/2*((t-=2)*t*t*t*t + 2) + b;
	},
	easeInSine: function (x, t, b, c, d) {
		return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
	},
	easeOutSine: function (x, t, b, c, d) {
		return c * Math.sin(t/d * (Math.PI/2)) + b;
	},
	easeInOutSine: function (x, t, b, c, d) {
		return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
	},
	easeInExpo: function (x, t, b, c, d) {
		return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
	},
	easeOutExpo: function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	},
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	},
	easeInCirc: function (x, t, b, c, d) {
		return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
	},
	easeOutCirc: function (x, t, b, c, d) {
		return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
	},
	easeInOutCirc: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
		return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
	},
	easeInElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
	},
	easeOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	},
	easeInOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
		return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
	},
	easeInBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*(t/=d)*t*((s+1)*t - s) + b;
	},
	easeOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
	},
	easeInOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158; 
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
	},
	easeInBounce: function (x, t, b, c, d) {
		return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
	},
	easeOutBounce: function (x, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	},
	easeInOutBounce: function (x, t, b, c, d) {
		if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
		return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
	}
});

/*
 *
 * TERMS OF USE - EASING EQUATIONS
 * 
 * Open source under the BSD License. 
 * 
 * Copyright © 2001 Robert Penner
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this list of 
 * conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list 
 * of conditions and the following disclaimer in the documentation and/or other materials 
 * provided with the distribution.
 * 
 * Neither the name of the author nor the names of contributors may be used to endorse 
 * or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE. 
 *
 */
 
 
 
 
 
 
