$(document).ready(function() {
	//Activate First Link
	$(".contentnav a:first").addClass("active");
	//width of a single content area
	var contentwidth = $(".contentholder").width();
	//Total number of content
	var totalcontent = $(".content").size();
	//Total width of all content area
	var allcontentwidth = contentwidth * totalcontent;
	//contentslider to new size which we got in above step
	$(".contentslider").css({'width' : allcontentwidth});
	//Now right a new function for slide and slide navigation
	rotate = function(){
	//Number of times we need to slide
	var slideid = $active.attr("rel") - 1;
	//Set the distance which single content needs to slide
	var slidedistance = slideid * contentwidth;
	//Remove active class
	$(".contentnav a").removeClass('active');
	//Add Active Class
	$active.addClass('active');
	//Slider Animation
	$(".contentslider").animate({
			left: -slidedistance
		}, 500 );
	}; 
	 
	//Set Time for Rotation of slide
	rotation = function(){
	play = setInterval(function(){
	//Next slide nav
	$active = $('.contentnav a.active').next();
	if ( $active.length === 0) {
	//Move to first slide nav
	$active = $('.contentnav a:first');
	}
	rotate();
	//Timer speed 5 sec
	}, 5000);
	};
	//Run rotation fuction
	rotation();
	$(".contentnav a").click(function() {
	$active = $(this);
	clearInterval(play);
	rotate();
	rotation();
	return false;
	});
	
	// Real time ticker
	setInterval(timeTicker, 1000);
	function timeTicker(){
		jQuery('div.price').each(function(){
			var sElem = jQuery(this).find('span.mysecond:eq(0)').text();
			var mElem = jQuery(this).find('span.myminutes:eq(0)').text();
			var hElem = jQuery(this).find('span.myhours:eq(0)').text();
			var dElem = jQuery(this).find('span.mydays:eq(0)').text();

			nS = parseInt(sElem, 10);
			nM = parseInt(mElem, 10);
			nH = parseInt(hElem, 10);
			nD = parseInt(dElem, 10);
			
			nS = nS - 1;
			if (nS < 0) {
				nM = nM - 1;
				if (nM < 0) {
					nH = nH - 1;
					if (nH < 0) {
						nD = nD - 1;
						if (nD < 0) {
							nS = 0;
							nM = 0;
							nH = 0;
							nD = 0;
						} else {
							nS = 59;
							nM = 59;
							nH = 23;
						}
					} else {
						nS = 59;
						nM = 59;
					}
				} else {
					nS = 59;
				}
			}
			
			if (nS<10 && nS >=0)
				nS="0" + nS;
			if (nM<10 && nM >=0)
				nM="0" + nM;
			if (nH<10 && nH >=0)
				nH="0" + nH;	
			if (nD<10 && nD >=0)
				nD="0" + nD;				

			jQuery(this).find('span.mysecond').text(nS);
			jQuery(this).find('span.myminutes').text(nM);
			jQuery(this).find('span.myhours').text(nH);            
			jQuery(this).find('span.mydays').text(nD);        
		});
	}
});
