/**
 * @author William
 */
function BackBtnClick(url){
	window.location=url;
	return false;
}

function swapImages(){
	var $active = $('.image-holder.slide');
	var $next = ($('.image-holder.slide').next().length > 0) ? $('.image-holder.slide').next() : $('.image-holder').first();
	var dfd =$('.image-holder.slide').next();

	
	$active.fadeOut(function(){
		//$active.removeClass('slide');
		$('.image-holder').removeClass('slide');
		$next.fadeIn().addClass('slide');	
	});
	

	//$active.hide();
	//$('.image-holder').removeClass('slide');
	//$next.show().addClass('slide');	
}
var intervalId;	

function positionThumbnail(){
	//IE
	if(!window.innerWidth)
	{
		//strict mode
		if(!(document.documentElement.clientWidth == 0))
		{
			w = document.documentElement.clientWidth;
			h = document.documentElement.clientHeight;
		}
		//quirks mode
		else
		{
			w = document.body.clientWidth;
			h = document.body.clientHeight;
		}
	}
	//w3c
	else
	{
		w = window.innerWidth;
		h = window.innerHeight;
	}

	if(w<1011){
		$('#header-number').addClass('header-number-small-window');
		$('#header-number').removeClass('header-number');
	}else{
		$('#header-number').removeClass('header-number-small-window');
		$('#header-number').addClass('header-number');
	}
}

$(document).ready(function(){	
	
	//show the first image
	var all = $('.image-holder');
	var $next = $(all[0]);
	$next.fadeIn().addClass('slide');	
	
	$(".header-number-single").click(function(){		
		var thumbnail = $(this).attr('id');		
		thumbnail = thumbnail.split('-');
		
		var $active = $('.image-holder.slide');
		var all = $('.image-holder');

		var $next = all[thumbnail[1]];
		$next = $($next);
	
		clearInterval(intervalId);
	
		$active.fadeOut(function(){
			//$active.removeClass('slide');
			$('.image-holder').removeClass('slide');
			$next.fadeIn().addClass('slide');	

		});
		
		//$active.hide();
		//$('.image-holder').removeClass('slide');		
		//$next.show().addClass('slide');	
		for(var i=0;i<all.length;i++){
			if(i!=thumbnail[1]){
				$(all[i]).removeClass('slide');
			}
		}
		intervalId = setInterval('swapImages()', 5000);

	});
	
	

	//intervalId = setInterval('swapImages()', 5000);	
	positionThumbnail();

	$(window).resize(function () { 
		positionThumbnail();

	});
});
