$(document).ready(function()
{
	if($('#productSelector').length)
	{
		$('ul.carousel').productSelector();
	}
});

function changeOption(id,src)
{
	var root = deriveRoot();
	$('img#'+id).attr("src",root+"media/images/product-selector/"+src);
}

$.fn.productSelector = function(settings)
{
	settings = $.extend({
		easeFunc: "expoinout",
		easeTime: 750,
		toolTip: false,
		order: new Array()
	},settings);
	
	var root = deriveRoot();
	var container = $(this);
	var slideWidth = container.find("li.productSelector").width();
	var slideCount = container.find("li.productSelector").size();
	var carouselWidth = slideWidth*slideCount;
	container.find("div#productSelector ul.carousel").css("width",carouselWidth);

	for(i=0; i<(slideCount-1); i++)
	{
		settings.order[i] = i+1;
	}

	var cslide 	= 1;
	
	$("li.0 a.option").unbind();

	$("li.0 a.option").bind('click', function()
	{
		skipTo('1','scroll',$(this).attr('href'));
		selectOption(this);
		return false;
	});
	
	$("li.0 a.forward").unbind();
	
	$("li.0 a.forward").bind('click', function()
	{
		skipTo('1','scroll',$(this).attr('href'));
		return false;
	});
	
	$("li.1 a.option").unbind();
	
	$("li.1 a.option").bind('click', function()
	{
		skipTo('2','scroll',$(this).attr('href'));
		selectOption(this);
		return false;
	});
	
	$("li.1 a.back").unbind();
	
	$("li.1 a.back").bind('click', function()
	{
		skipTo('0','scroll',$(this).attr('href'));
		$("li.0 a").removeClass("noShow");
		clearOption();
		return false;
	});
	
	$("li.1 a.forward").unbind();
	
	$("li.1 a.forward").bind('click', function()
	{
		skipTo('2','scroll',$(this).attr('href'));
		return false;
	});
	
	$("li.2 a.option").unbind();
	
	$("li.2 a.option").bind('click', function()
	{
		skipTo('2','scroll',$(this).attr('href'));
		selectOption(this);
		return false;
	});
	
	$("li.2 a.back").unbind();
	
	$("li.2 a.back").bind('click', function()
	{
		skipTo('1','scroll',$(this).attr('href'));
		$("li.1 a").removeClass("noShow");
		return false;
	});
	
	$("a#option3").unbind();
	
	$("a#option3").bind('click', function()
	{
		skipTo('2');
		return false;
	});
	
	function skipTo(slide,type,href)
	{
		type = typeof(type) != 'undefined' ? type : 'scroll';
		var cnt = - (slideWidth*(slide));
		var root = deriveRoot();
		
		if(type == 'scroll')
		{
			$("ul.carousel ").animate({ left: cnt }, settings.easeTime, settings.easeFunc);
		}
		else
		{
			$("ul.carousel").css("left",cnt);
		}
		
		$.post(root+"productSelector.php", 
		{
			href: href
		},
		function(data){ $('div.ajaxDiv').html(data); return false; });
	}
	
	function selectOption(selection)
	{
		var newSelectionID = $(selection).find("img").attr('id');
		var oldSelectionID = $("li a.current").find("img").attr("id");
		
		$("li a.current").find("img").attr("src", root+"media/images/product-selector/ps-"+oldSelectionID+".gif");
		$("li a.current").attr("onmouseover", "changeOption('"+oldSelectionID+"','ps-"+oldSelectionID+"-over.gif')");
		$("li a.current").attr("onmouseout", "changeOption('"+oldSelectionID+"','ps-"+oldSelectionID+".gif')");
		$("li a.current").removeClass("current");
		
		$(selection).find("img").attr("src", root+"media/images/product-selector/ps-"+newSelectionID+"-over.gif");
		$(selection).attr("onmouseover", "");
		$(selection).attr("onmouseout", "");
		$(selection).addClass("current");
	}
	
	function clearOption() 
	{
		var oldSelectionID = $("li a.current").find("img").attr("id");
		
		$("li a.current").find("img").attr("src", root+"media/images/product-selector/ps-"+oldSelectionID+".gif");
		$("li a.current").attr("onmouseover", "changeOption('"+oldSelectionID+"','ps-"+oldSelectionID+"-over.gif')");
		$("li a.current").attr("onmouseout", "changeOption('"+oldSelectionID+"','ps-"+oldSelectionID+".gif')");
		$("li a.current").removeClass("current");	  
	}
};

/*
 * jQuery EasIng v1.1.2 - http://gsgd.co.uk/sandbox/jquery.easIng.php
 *
 * Copyright (c) 2007 George Smith
 * Licensed under the MIT License:
 *   http://www.opensource.org/licenses/mit-license.php
 */
eval(function(p,a,c,k,e,d){e=function(c){return(c<a?"":e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c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*2,0,c,d)*.5+b;6 l.n.v(x,t*2-d,0,c,d)*.5+c*.5+b}});',62,71,'||||||return||Math|function|||||if|var|PI|pow|75|70158|else|jQuery|sin|easing|sqrt||5625|abs|||asin|easeOutBounce|undefined||525|easeInBounce|cos|easeInOutQuint|easeOutSine|easeInOutSine|easeOutExpo|easeInOutExpo|easeOutQuint|easeInOutBack|easeInCirc|25|easeInElastic|9375|easeInSine|easeInOutElastic|easeInQuart|easeOutCubic|625|easeInOutCubic|easeInOutQuart|984375|easeInOutQuad|easeOutQuad|easeInOutBounce|easeOutElastic|extend|easeInBack||easeInOutCirc|easeOutCirc|easeOutQuart|easeOutBack|easeInQuad|easeInExpo|easeInCubic|easeInQuint'.split('|'),0,{}))

/*
 * jQuery Easing Compatibility v1 - http://gsgd.co.uk/sandbox/jquery.easing.php
 *
 * Copyright (c) 2007 George Smith
 * Licensed under the MIT License:
 *   http://www.opensource.org/licenses/mit-license.php
 */
eval(function(p,a,c,k,e,d){e=function(c){return(c<a?"":e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('0.C(0.1,{7:2(x,t,b,c,d){3 0.1.D(x,t,b,c,d)},5:2(x,t,b,c,d){3 0.1.6(x,t,b,c,d)},h:2(x,t,b,c,d){3 0.1.B(x,t,b,c,d)},A:2(x,t,b,c,d){3 0.1.m(x,t,b,c,d)},y:2(x,t,b,c,d){3 0.1.w(x,t,b,c,d)},v:2(x,t,b,c,d){3 0.1.u(x,t,b,c,d)},s:2(x,t,b,c,d){3 0.1.r(x,t,b,c,d)},q:2(x,t,b,c,d){3 0.1.p(x,t,b,c,d)},o:2(x,t,b,c,d){3 0.1.n(x,t,b,c,d)},8:2(x,t,b,c,d){3 0.1.l(x,t,b,c,d)},g:2(x,t,b,c,d){3 0.1.j(x,t,b,c,d)},i:2(x,t,b,c,d){3 0.1.k(x,t,b,c,d)},z:2(x,t,b,c,d){3 0.1.f(x,t,b,c,d)},e:2(x,t,b,c,d){3 0.1.a(x,t,b,c,d)},9:2(x,t,b,c,d){3 0.1.4(x,t,b,c,d)}});',40,40,'jQuery|easing|function|return|easeInOutBack|easeOut|easeOutQuad|easeIn|elasin|backinout|easeOutBack||||backout|easeInBack|elasout|easeInOut|elasinout|easeOutElastic|easeInOutElastic|easeInElastic|easeInExpo|easeInOutBounce|bounceinout|easeOutBounce|bounceout|easeInBounce|bouncein||easeInOutExpo|expoinout|easeOutExpo||expoout|backin|expoin|easeInOutQuad|extend|easeInQuad'.split('|'),0,{}))