			/* 
			
			LXY Brands interactivity 
			---------------------------
			Author:			Sam Hampton-Smith
							Hampton-Smith Limited
			Email:			sam@hampton-smith.com
			URL:			www.hampton-smith.com
			-------------------------------------
			
			All code designed to ensure pages will continue to work with JavaScript disabled unless otherwise noted
			
			This code copyright 2010 Hampton-Smith Limited
			
			*/

			/* Some basic settings to allow these values to persist to an unreferenced function */
			var carosel_speed = 3000;
			var carosel_item_width;
			var carosel_left_value;			


			$(document).ready(function(){
									   
				/* Drawer panels */
				$(".slideout").delay(1000).each(function(n){
					$(this).delay(100*n).animate({left:-156},600);
				});
				$(".slideout").hover(function(){
					$(this).stop().animate({left:0},600);							  
											  },
											  function(){
					$(this).stop().animate({left:-156},600);							
				});
				
				$("#newssections a").hover(function(){
					var targetoffset = $(this).offset();
					var container = $("#newssections ul").offset();
					var targettop = targetoffset.top-container.top;	
					$("#newssections ul").stop().animate({backgroundPosition:"15px "+(targettop)+"px"},600);
				},function(){
					var targetoffset = $("#newssections a.active").offset();
					var container = $("#newssections ul").offset();
					var targettop = targetoffset.top-container.top;	
					$("#newssections ul").stop().animate({backgroundPosition:"15px "+(targettop)+"px"},600);					
				});
				
				$("#newssections a").click(function(){
					$("#newssections a").removeClass("active");
					$(this).addClass("active");
					var target = $(this).attr("href");
					var targetoffset = $(target).offset();
					var container = $("#newsslider").offset();
					var targetleft = container.left-targetoffset.left;
					var targettop = container.top-targetoffset.top;
					/* $("#newsslider").animate({top:targettop,left:targetleft},600); */
					if (target=="#contentwindow") {
						$("#videocontentpanel").animate({opacity:0},600,function(){$(this).css({top:400,left:0,opacity:0});});
						$("#currentnewspanel").animate({opacity:1});
					} else {
						$("#videocontentpanel").css({top:0,left:0,zIndex:500,opacity:0}).animate({opacity:1});
						$("#currentnewspanel").animate({opacity:0});

					}
					return false;						   
				});
				
				/* Content slider - one page many panels functionality - slide to selected panel */
				
				$("#currentnewspanel a").click(function(){
					$("#currentnewspanel a").removeClass("active");
					$(this).addClass("active");
					var target = $(this).attr("href");
					var targetoffset = $(target).offset();
					var container = $("#contentpanels").offset();
					var targetleft = container.left-targetoffset.left;
					var targettop = container.top-targetoffset.top;
					$("#contentpanels").animate({top:targettop,left:targetleft},600);
					return false;						   
				});
				
				/* Duplicate of the above - could be rationalised */
				
				$("#linkspanel a").click(function(){
					$("#linkspanel a").removeClass("active");
					$(this).addClass("active");
					var target = $(this).attr("href");
					var targetoffset = $(target).offset();
					var container = $("#contentpanels").offset();
					var targetleft = container.left-targetoffset.left;
					var targettop = container.top-targetoffset.top;
					$("#contentpanels").animate({top:targettop,left:targetleft},600);
					return false;						   
				});				
				
				/* Image carosel */
				$("#carosel").each(function(){
					if($('#carosel.collection').length) {
						carosel_speed = 5500;
					}
					$('#carosel li:last').after($('#carosel li:first'));						
					carosel_item_width = $('#carosel li').outerWidth();   
					carosel_left_value = ((carosel_item_width) * (-1))-6;
					$('#carosel ul').css({'margin-left' : carosel_left_value}); 
					var run = setInterval('caroselrotate()', carosel_speed);  							
				});
				
				/* Cool Button depress effect */				
				$("#quicknav li a").hover(function(){$(this).parents("li").animate({"margin-top":2,opacity:0.8},200);},function(){$(this).parents("li").animate({"margin-top":0,opacity:1},200);});
				
				
				/* Allow all brand pages to work from first page by loading subsequent pages in dynamically */
				$("#brandnav a.next").live("click", function(){
					var page = $(this).attr("href");
					function doSomethingWithData(data) {
						$("#innercontentpanel").wrap("<div id='tempsliderouter'><div id='tempslider'></div></div>");
						var newcontent = $(data).find("#innercontentpanel");
						$(newcontent).attr("id","innercontentpanel2");
						$("#innercontentpanel").css({float:"left", marginLeft:0}).after(newcontent);
						$("#innercontentpanel2").css({float:"left",marginLeft:0});
						$("#innercontentpanel").animate({marginLeft:-956},700,function(){
																  
								// remove tempslider
								// remove #innercontentpanel
								// rename €innercontentpanel2
								$("#innercontentpanel").remove();
								$("#innercontentpanel2").attr("id","innercontentpanel");
								$("#innercontentpanel").unwrap().css({marginLeft:10}).unwrap();
						})
					} 
					$.get(page, doSomethingWithData);
					
					return false;
				});
				$("#brandnav a.prev").live("click", function(){
					var page = $(this).attr("href");
					function doSomethingWithData(data) {
						$("#innercontentpanel").wrap("<div id='tempsliderouter'><div id='tempslider'></div></div>");
						var newcontent = $(data).find("#innercontentpanel");
						$(newcontent).attr("id","innercontentpanel2");
						$("#innercontentpanel").css({float:"left", marginLeft:0}).before(newcontent);
						$("#innercontentpanel2").css({float:"left",marginLeft:-946});
						$("#innercontentpanel2").animate({marginLeft:0},700,function(){
																  
								// remove tempslider
								// remove #innercontentpanel
								// rename #innercontentpanel2
								$("#innercontentpanel").remove();
								$("#innercontentpanel2").attr("id","innercontentpanel");
								$("#innercontentpanel").unwrap().css({marginLeft:10}).unwrap();
						})
					} 
					$.get(page, doSomethingWithData);
					
					return false;
				});
				
				/* Load product pages dynamically and swipe them into view. */
				
				$("#productlist a").live("click", function() {
					oldheight=$(".innercontentcatalogue").outerHeight();
					$(".innercontentcatalogue").css({height:oldheight});
					var page = $(this).attr("href");
					$("#productlist").css({marginLeft:-10,float:"left"}).wrap("<div id='shopslideouter'><div id='shopslide'></div></div>");
					$("#shopslide").append("<div id='newcontent'></div>");
					$("#newcontent").load(page + " #productdetail");
					$("#shopslide").animate({marginLeft:-956},700, function(){			
						/* Animate to height of product page */													
						$(".innercontentcatalogue").animate({height:555});														
						/* Note we keep the catalogue page to avoid unncessary reloads and quick transition back */													
					});
					
					/* If the product page is shown inside the category page, allow us to go back to category with swipe */
					
					$("#backtocat").live("click", function(){
						$("#shopslide").animate({marginLeft:0},700, function(){
							/* Remove the product page area */
							$("#newcontent").remove();
							$("#productlist").unwrap().css({marginLeft:0}).unwrap();
							/* Go back to original height for category */
							$(".innercontentcatalogue").animate({height:oldheight});	
						});
						
						return false;
					});
					
					return false;
				});
				
				
				/* Product Image Viewer */
				
				$("#viewer").live("mouseover", function(){
					if ($("#shopslide:animated").length) {
						// Still animating so don't do the big image thing	
					} else {
						var img = $("#imagespanel img").attr("src");
						img = img.replace("resizeimage.asp?x=460&image=","");
						$("#imagespanel").stop().css({backgroundImage:"url('images/"+img+"')"});
						$("#imagespanel img").animate({opacity:0});
					}
				});
				$("#viewer").live("mouseout", function(){
					$("#imagespanel img").animate({opacity:1},600,function(){
						//$("#imagespanel").css({backgroundImage:"url(styles/70.gif)"});
					});
					if ($("#shopslide:animated").length) {
						// Still animating so don't do the big image thing	
					} else {
						$("#imagespanel").css({backgroundPosition:"center center"});
					}
				});
				
				$("#viewer").live("mousemove",function(e){
					var offset = $("#viewer").offset();
					var x = e.pageX - offset.left;
					var y = e.pageY - offset.top;
					
					/* Limits to the bounds of the feedback */
					if (y>105) y=105;
					var positionx = -1*(x/105)*1380;
					var positiony = -1*(y/105)*1380;
					positionx = positionx + 230;
					positiony = positiony + 230;
					if (positionx>0) positionx=0;
					if (positiony>0) positiony=0;
					if (positionx<-920) positionx=-920;
					if (positiony<-920) positiony=-920;
					
					if ($("#shopslide:animated").length) {
						// Still animating so don't do the big image thing	
					} else {
						/* Animate into position to smooth out jerky feedback */
						$("#imagespanel").stop().animate({backgroundPosition:positionx+" "+positiony},100);
					}
				});
				
				/* Groovy Submit Buttons */
				
				$("#submit").live("mouseover", function(){
					$(this).stop().animate({backgroundPosition:"-20 0"},500);										
				});
				
				$("#submit").live("mouseout", function(){
					$(this).css({backgroundPosition:"-120px 0px"}).stop().animate({backgroundPosition:"-120 -80"},500, function(){$(this).css({backgroundPosition:"-20px -80px"})});										
				});
				
				$("#mybutton").live("mouseover", function(){
					$(this).stop().animate({backgroundPosition:"-20 0"},500);										
				});
				
				$("#mybutton").live("mouseout", function(){
					$(this).css({backgroundPosition:"-120px 0px"}).stop().animate({backgroundPosition:"-120 -80"},500, function(){$(this).css({backgroundPosition:"-20px -80px"})});										
				});
				
				/* Stockist List */
				// Note Stockists page will not work without JS currently
				
				$("#stockistlist ul").hide();
				
				$("#stockists ul").live("mouseover",function(e){
					target = e.target;
					offset = $(this).offset();		
					mycontainer = $("#stockists").offset();
					//container = $(this).parents("div").offset();
					position = parseInt(offset.left)-parseInt(mycontainer.left);
					//console.log(position);
					if (position<0) {
						alreadymargin = parseInt($("#stockistlist").css("margin-left"));
						if ($(this).attr("id")=='stockistlist') alreadymargin=alreadymargin-20;
						$("#stockistlist").not(":animated").animate({marginLeft:alreadymargin+(position*-1)+23},600,function(){	$("#stockists ul").css({backgroundImage: "none"});});
					}
				});
				
				$("#stockists ul div").live("mouseover",function(){
					$(this).parent("li").parent("ul").css({backgroundImage: "url(styles/stockistsback.gif)",backgroundRepeat: "no-repeat",backgroundPosition: "120px 0px"});
					offset = $(this).offset();	
					mycontainer = $("#stockists").offset();
					position = parseInt(offset.left)-parseInt(mycontainer.left);
					//console.log(position);
					if (position>12) {
						alreadymargin = parseInt($("#stockistlist").css("margin-left"));
						$("#stockistlist").not(":animated").animate({marginLeft:alreadymargin+(position*-1)+23});
					}											 
				});
				
				$("#stockistlist li").live("click",function(){
					$(this).css({backgroundColor:"#ddd"}).siblings("li").css({backgroundColor:"transparent"});
					$("#stockistlist ul").hide();
					$("#stockistlist div").hide();
					$(this).children("ul").show().parents("ul").show();
					$(this).children("ul").children("li").css({backgroundColor:"transparent"});
					$(this).children("div").show().parents("ul").show();
					offset = $(this).children("ul").offset();
					offsetwidth = $(this).children("ul:visible:last").width();
					//alert(offset);
					if (offset == null) {
						offset = $(this).children("div").offset();
						offsetwidth = $(this).children("div").width();
					}
					mycontainer = $("#stockists").offset();
					position = parseInt(offset.left)-parseInt(mycontainer.left);
					if (position<0) position=position*-1;
					position = position + (offsetwidth-413);
					alreadymargin = parseInt($("#stockistlist").css("margin-left"));
					$("#stockistlist").animate({marginLeft:alreadymargin+(position*-1)});
					
				});
				
				/* Scrollbar areas */
				$('#scroller').jScrollPane({showArrows:true});
				
				/* Footer email frm */
				$("#footerform #email").click(function(){
					if ($(this).val()=='enter email address') {
						$(this).val("");
					}
				});
				
				
				/* Popup panels over the product page */
				
				$("#buyextra li a").live("click", function(){
					target = $(this).attr("href");
					$("#buyextra").after("<div id='popup'></div>");
					$("#popup").load(target + " .innercontentliner #wrap",{},function(){$('#scroller').jScrollPane({showArrows:true});$(this).append("<a href='#' title='Click here to close this window'>close</a>");}).css({opacity:0.9});	
					$("#popup > a").live("click",function(){
						$("#popup").remove();	
						return false;
					});
					return false;
				});
				
				/* show correct stock options */
				
				$("#infopanel select").live("change", function(e){
						// do something - it's a product option
						if(e.target.id=="itemqty") {
							// do nothing 
						} else {
						var mystring = "catalogue_b.asp?action=showproduct&productid=" + $("#productid").val()+"&catid="+$("#catid").val();
						$("#infopanel select").each(function(){
							//alert($(this).attr("id"));
							mystring = mystring + "&" + $(this).attr("id") + "=" + $(this).val();														  
						});
						$("#infopanel form").load(mystring + " #infopanel form");
						//alert(mystring);
						}
				});
				if ($.browser.msie) {
					  $("#infopanel select").live("click",function(e){
						//alert("detected a change");
						// do something - it's a product option
						if (e.target.id=="itemqty") { } else {
							//alert($(e.target).data("oldval") + " " + $(e.target).val());
							if ($(e.target).val()==$(e.target).data("oldval")) {
								// do nothing 
							} else {
						var tempstring = "";
						var mystring = "catalogue_b.asp?action=showproduct&productid=" + $("#productid").val()+"&catid="+$("#catid").val();
						$("#infopanel select").each(function(){
							//alert($(this).attr("id"));
							$(this).data("oldval",$(this).val());
							tempstring = tempstring + "$('#" + $(this).attr("id") + "').val('" + $(this).val() + "');"
							mystring = mystring + "&" + $(this).attr("id") + "=" + $(this).val();														  
						});
						$("#infopanel form").load(mystring + " #infopanel form",{},function(){eval(tempstring);$("#infopanel select").each(function(){$(this).data("oldval",$(this).val())})});
						//alert(mystring);
							}
						}
				});
				}

				
				
			});
			
	
		
			function caroselrotate() {
				var carosel_left_indent = parseInt($('#carosel ul').css('margin-left')) - carosel_item_width;  
				$('#carosel ul').animate({'margin-left' : carosel_left_indent}, 2000, function () {  
					$('#carosel li:last').after($('#carosel li:first'));                    
					$('#carosel ul').css({'margin-left' : carosel_left_value});  
				});  
				return false;  
			}
			