	$(document).ready(function(){		
		
		if ($("#counter").length > 0) {
			$('#lez #counter').countdown({
	          image: '/img/lez/digits.png',
	          startTime: countDownTime(2012,0,3)
	        });
	      }
        
		$("#lez").click(function(){
			location.href = $(this).children("a").attr("href");
		});
		$('#slideshow').cycle({
			fx: 'fade',
			speed:  1000,
			timeout:  5000,
			pause: 1
		});
		
		$('#brandSlideshow').cycle({
			fx: 'fade',
			speed:  1000,
			timeout:  5000,
			pause: 1
		});
		
		$('.specialOfferCont').cycle({
			fx: 'scrollUp',
			speed:  500,
			timeout:  5000,
			pause: 1
		});
		
		$(".cin-link").click(function(){
			location.href='/news/18/were-raising-money-for-children-in-need';
		});		
		
		cinDisplay();
		
		if ($("#usedFilterForm").length) {		
		
			$("#usedFilterForm").formidable({
				form: {
					fieldsetPadding: 10,  
					font: '0.8em Segoe UI, Verdana, sans-serif',  
					width: 163,  
					padding: 5  
				}
			});
			
			$("#usedFilterForm select").change(function(){
				$(this).parent().parent("form").submit();
			});
			
		}
		
		if ($("#contactForm").length) {		
		
			$("#contactForm").formidable({
				form: {
					fieldsetPadding: 10,  
					font: '0.8em Segoe UI, Verdana, sans-serif',  
					width: "98%",  
					padding: 5  
				}
			});
			
			$("#contactForm").submit(function(){
				var complete = true;
				$(this).children("input,textarea").each(function(index, field) {
					if (!$(field).val()){
						complete = false;
						$(field).addClass("error");	
					} else {
						$(field).removeClass("error");	
					}
				});
				if (!complete) {
					alert("Please complete all fields.");
					
				} else {
					$.ajax({
						url: $(this).attr("action"),
						type: "POST",
						dataType: "json",
						data: $(this).serialize(),
						success: function(data) {
							$("#contactForm").hide();
							$("#response").fadeIn();	
						}
							
					});	
				}
				
				return false;	
			});
			
		}
		
		if ($("#usedPhotos").length) {
		
			$.fn.cycle.updateActivePagerLink = function(pager, currSlideIndex) { 
			    $(pager).find('li').removeClass('activeSlide').filter('li:eq('+currSlideIndex+')').addClass('activeSlide');
			    $(pager).scrollTo(".activeSlide", 500, { offset: -50 });			     
			}; 		
		
			$('#usedPhotos').cycle({ 
			    fx:     'scrollLeft', 
			    speed:  'fast', 
			    timeout: 0, 
			    pager:  '#usedPhotosNav',
			    next: '#usedPhotos img',
			    pagerAnchorBuilder: function(idx, slide) {
			        return '#usedPhotosNav li:eq(' + idx + ') a'; 
			    } 
			});
			
			
			
		}
		
		$(window).resize(function(){
			cinDisplay();
		});
		
	});
	
	function cinDisplay() {
		if ($(window).width() > 1500) {
			$("#cin-small").hide();
			$("#cin-medium").hide();
			$("#cin").show();
		}
		else
		{
			if ($(window).width() > 1300) {
				$("#cin-small").hide();
				$("#cin").hide();		
				$("#cin-medium").show();
			}
			else
			{
				$("#cin").hide();
				$("#cin-medium").hide();
				$("#cin-small").show();	
			}
		}	
	}
	
	function countDownTime(year,month,day) {
		var end = new Date(year,month,day,0,0,0);
		var today = new Date();
		
		var time_left = today.getTime()-end.getTime();	
		
		var one_minute = 1000*60;
		var one_hour = one_minute*60;
		var one_day = one_hour*24;
		
		var days = Math.floor((time_left)/(one_day));

		days += 1;
		days = days + '';
		days = days.replace("-","");
		
		var hours = 24 - today.getHours();
		var minutes = 60 - today.getMinutes();
		var seconds = 60 - today.getSeconds();
		
		if (hours < 10) {
			hours = "0" + hours;
		}	
		
		if (minutes < 10) {
			minutes = "0" + minutes;
		}	
		
		if (seconds < 10) {
			seconds = "0" + seconds;	
		}		
		
		return days + ":" + hours + ":" + minutes + ":" + seconds;
	}

