$(document).ready(function() {


  $("#id_deliverhere").change(function () {

    if ($("#id_deliverhere")[0].checked) {
      $('#deliverydetails').animate({ opacity: 0}, 500 );
  	}
  	else {
      $('#deliverydetails').animate({ opacity: 1}, 500 );
  	}
  });

	$("#refreshHome").click(function() {		
		homeImageIndex++;

		if(homeImageIndex > homeImages.length-1) {
			homeImageIndex = 0;
		}
		var nextImageSrc  = homeImages[homeImageIndex];

		var preload	 = new Image();
		preload.onload = function() {
			$("#homePlayerImg").fadeOut(500,function() {
				$(this).css({backgroundImage: "url("+nextImageSrc+")"}).fadeIn(500)
			})
		}
		preload.src = nextImageSrc;		
		return false;
	});	
	
	$("#scrollingThumbs a").click(function() {
		$("#scrollingThumbs a").removeAttr("class");
		$(this).attr("class","selected");
		return false;
	});
	
	/*
	$("#scrollingThumbs.images a").click(function() {
		
	});	
*/
	$("#fullSize a").click(function() {
		return false;
	});

	$("#fullSize a").lightBox();



	$("#productImage a").click(function() {
		return false;
	});

	$("#productImage a").lightBox();

	$("#scrollingThumbs.videos a").click(function() {
		var videoID = $(this).attr("href");
		$.getJSON(
			"get_video.php?",
			{videoID:videoID},
			function(json) {
				$("#vTitle").text(json.title);	
				$("#vCopyright").text(json.copyright);	   			
				$("#vFeaturedIn").text(json.featured).attr("href",json.featuredlink);
				var so = new SWFObject(json.swf, "videoSwf", json.width, json.height, "8", "#ffffff");
				so.write("videoRight");
			}
		);
		return false	
	});

	
});



/* Scrolling Thumbs */
function ScrollingThumbs(targID) {	
	
	var self = this;
	this.thumbWidth			= 103;
	this.onscreen			= 6;
	this.currPosition		= 0;
	this.speed				= 300;
	this.thumbCount			= $("#"+targID+" ul li").size();
	this.scrollableWidth 	= self.thumbCount * self.thumbWidth;
	this.xPositions			= new Array();
	for(i=0;i<=(self.thumbCount-self.onscreen);i++) {
		this.xPositions[i] = (i * - self.thumbWidth) + "px";
	}
	
	$("#scrollingThumbs ul").css({width:self.scrollableWidth + "px",left:"0px"});
	$("#"+targID).css("overflow","hidden")
	
	
	
	$("#leftBtn").click(function() {
		rightScroll();
		return false;
	});
	$("#rightBtn").click(function() {
		leftScroll();
		return false;
	});
	
	this.leftScroll = leftScroll;
	function leftScroll() {					
		if(self.currPosition < self.xPositions.length-1) {
			self.currPosition ++;
			$("#scrollingThumbs ul").animate({left: self.xPositions[self.currPosition]},self.speed)
		} 		
	}
	
	this.rightScroll = rightScroll;
	function rightScroll() {
		if(self.currPosition > 0) {
			self.currPosition --;
			$("#scrollingThumbs ul").animate({left: self.xPositions[self.currPosition]},self.speed)
		} 		
	}

	
	
}