var CURRENCY = '&pound;';

$(document).ready(function()
{
	$('h2.twitter').fadeIn();
	
	$('a[rel="external"]').click(function()
	{
		open($(this).attr('href'));
		return false;
	});
	
	$('a[rel="nofollow external"]').click(function()
	{
		open($(this).attr('href'));
		return false;
	});
  
	$('#nav').superfish({});
	
	$('input#keywords').focus(function()
	{
		if(this.value == 'Search')
		{
			this.value = '';
		}
	});
	
	$('input#keywords').blur(function()
	{
		if(this.value == '')
		{
			this.value = 'Search';
		}
	});
	
	$('form.mailing-list input#mailing_list_email_address').focus(function()
	{
		if(this.value == 'Email Address')
		{
			this.value = '';
		}
	});
	
	$('form.mailing-list input#mailing_list_email_address').blur(function()
	{
		if(this.value == '')
		{
			this.value = 'Email Address';
		}
	});
	
	// Carousel
	if($('div#carousel').length)
	{
		$('div#carousel').carousel();
	}
	
	//$('label.overlabel').overlabel();
	
	// Basket Functionality
	activateRemoveLinks(_root);
	activateAddLinks(_root);
	activateProductConfigurators(_root);
	
	// Quick Find Functionality
	activateQuickFind(_root);
	
	enableLightboxes(_root);
	
	// Image Changer
	$('dl.productImages li a').hover(function()
	{
		removeMagnifyingGlass();
		var href = $(this).attr('href');
		var src  = $(this).find('img').attr('src');
		src = src.replace('thumb/','');
		src = src.replace(/_thumb/,'');
		$('dl.productImages dt a').attr('href',href);
		$('dl.productImages dt img').attr('src',src);
		addMagnifyingGlass(_root);
	},function(){});
	
	// Checkout
	if(!$.browser.msie) // IE won't play nice...
	{
	    // Welcome Sign In
	    if($('input#registeredN').is(':checked'))
	    {
			$('form#checkoutWelcome span#hide').hide();
			$('form#checkoutWelcome input#password').hide();
			$('a#forgottenPass').hide();
	    }
		
	    $('input[name="registered"]').change(function()
	    {
			if($('input#registeredY').is(':checked'))
			{
				$('form#checkoutWelcome span#hide').show();
				$('form#checkoutWelcome input#password').show();
				$('form#checkoutWelcome li#passParent span.warning').show();
				$('a#forgottenPass').show();
			}
			else
			{
				$('form#checkoutWelcome span#hide').hide();
				$('form#checkoutWelcome input#password').hide();
				$('form#checkoutWelcome li#passParent span.warning').hide();
				$('a#forgottenPass').hide();
			}
	    });
	    
	    // Billing Address
	    if($('input#deliverySame').is(':checked'))
	    {
			$('fieldset#newDelivery').hide();
	    }
	    
	    $('input[name="deliveryAddr"]').change(function()
	    {
			if($('input#deliverySame').is(':checked'))
			{
				$('fieldset#newDelivery').hide();
			}
			else
			{
				$('fieldset#newDelivery').show();
			}
	    });
	}
	
	$('select#billing_country').change(function()
	{
		if($(this).children("[selected]").hasClass('overseas'))
		{
			$('input#deliverySame').attr('checked', 'checked');
			$('fieldset#newDelivery').hide();
			$('fieldset.yourDeliveryAddress').hide();
		}
		else
		{
			$('fieldset.yourDeliveryAddress').show();
		}
	});
	
	// Form Help Tips
	createHelpTips();
	activateHelpTips();
	
	// Make Product Boxes Equal Height...
	if($('body').attr('id') != 'freegift')
	{
		$('ul.products').each(function()
		{
		    var line_height = 0;
			
			$(this).children('li').each(function()
		    {
				if($(this).height() > line_height)
				{
					line_height = $(this).height();
				}
		    });
		    
		    $(this).children('li').each(function()
		    {
				var desc_padding = ((line_height - $(this).height()) + 2);
				
				$(this).css('height',line_height+'px');
				
				$(this).find('div.desc').css('paddingBottom',desc_padding);
		    });
		});
		
		if($.browser.msie) // Cannot vertically align images so add margin as required
		{
			$('ul.products div.image span img').each(function()
			{
				if(this.load && this.height < 150)
				{
					var margin_top =((150 - this.height) / 2);
					$(this).css('marginTop',margin_top);
				}
			});
		}
	}
});

/*
 * Superfish v1.4.1 - jQuery menu widget
 * Copyright(c) 2008 Joel Birch
 * Dual licensed under the MIT and GPL licenses:
 *  http://www.opensource.org/licenses/mit-license.php
 *  http://www.gnu.org/licenses/gpl.html
 * CHANGELOG: http://users.tpg.com.au/j_birch/plugins/superfish/changelog.txt
 */
(function($)
{
	$.superfish = {};
	$.superfish.o = [];
	$.superfish.op = {};
	$.superfish.defaults = {
	    hoverClass : 'sfHover',
	    pathClass : 'overideThisToUse',
	    delay : 600,
	    animation : {opacity:'show',height:'show'},
	    speed : 'fast',
	    oldJquery : false,
	    disableHI : false,
	    // callback functions:
	    onInit : function(){},
	    onBeforeShow : function(){},
	    onShow : function(){},
	    onHide : function(){}
	};
	$.fn.superfish = function(op){
	    var bcClass = 'sfbreadcrumb',
			over = function()
			{
		        var $$ = $(this), menu = getMenu($$);
		        getOpts(menu,true);
		        clearTimeout(menu.sfTimer);
		        $$.showSuperfishUl().siblings().hideSuperfishUl();
			},
			out = function()
			{
		        var $$ = $(this), menu = getMenu($$);
		        var o = getOpts(menu,true);
		        clearTimeout(menu.sfTimer);
		        if(!$$.is('.'+bcClass))
				{
					menu.sfTimer=setTimeout(function()
					{
			            $$.hideSuperfishUl();
			            if(o.$path.length){over.call(o.$path);}
					},o.delay);
		        }
			},
			getMenu = function($el){ return $el.parents('ul.superfish:first')[0]; },
			getOpts = function(el,menuFound){ el = menuFound ? el : getMenu(el); return $.superfish.op = $.superfish.o[el.serial]; },
			hasUl = function(){ return $.superfish.op.oldJquery ? 'li[ul]' : 'li:has(ul)'; };
			
			return this.each(function()
			{
				var s = this.serial = $.superfish.o.length;
				var o = $.extend({},$.superfish.defaults,op);
				o.$path = $('li.'+o.pathClass,this).each(function()
				{
					$(this).addClass(o.hoverClass+' '+bcClass)
					.filter(hasUl()).removeClass(o.pathClass);
				});
				$.superfish.o[s] = $.superfish.op = o;
				
				$(hasUl(),this)[($.fn.hoverIntent && !o.disableHI) ? 'hoverIntent' : 'hover'](over,out)
				.not('.'+bcClass)
				.hideSuperfishUl();
				
				var $a = $('a',this);
				$a.each(function(i)
				{
					var $li = $a.eq(i).parents('li');
					$a.eq(i).focus(function(){over.call($li);}).blur(function(){out.call($li);});
				});
				
				o.onInit.call(this);
			}).addClass('superfish');
	};
	
	$.fn.extend(
	{
	    hideSuperfishUl : function()
		{
			var o = $.superfish.op,
	        $ul = $('li.'+o.hoverClass,this).add(this).removeClass(o.hoverClass)
	        .find('>ul').hide().css('visibility','hidden');
			o.onHide.call($ul);
			return this;
	    },
	    showSuperfishUl : function()
		{
			var o = $.superfish.op,
			$ul = this.addClass(o.hoverClass)
	        .find('>ul:hidden').css('visibility','visible');
			o.onBeforeShow.call($ul);
			$ul.animate(o.animation,o.speed,function(){ o.onShow.call(this); });
			return this;
	    }
	});
	
	$(window).unload(function()
	{
		$('ul.superfish').each(function()
		{
			$('li',this).unbind('mouseover','mouseout','mouseenter','mouseleave');
		});
	});
})(jQuery);

// Overlabel - Accessible Text Input Labels For Space Saving Forms
(function($)
{
	$.fn.overlabel = function()
	{
		this.each(function()
		{
			var label = $(this);
			var id = this.htmlFor || label.attr('for') || 'NO-ID';
			$('#'+id.replace(/\:/,'\\:'))
			.parent().addClass('overlabel-wrapper').end()
			.focus(function(){ label.css('text-indent','-9999px'); })
			.blur(function(){ this.value || label.css('text-indent','0px'); })
			//.trigger('focus').trigger('blur')  CAUSING PAGE TO JUMP TO FOOTER????
			.length && 
			label.addClass('overlabel-apply');
		});
	}
})(jQuery);

// BASKET FUNCTIONS
function animateBasket(action)
{
	switch(action)
	{
	    case 'add':
			colour = '#00BF08';
	    break;
	    case 'delete':
			colour = '#FF4A4A';
	    break;
	}
	
	$('li#updated').highlightFade({colour:colour,iterator:'exponential'});
}

function activateRemoveLinks(_root)
{
	$('a.del').click(function()
	{
		if($(this).hasClass('fg')) // Free gift so return true to refresh page
		{
			return true;
		}
		else
		{
		    $.get(_root+'basket/',
		    {
				removeItem  : $(this).attr('id').substring(10),
				ajax        : 'true'
		    },
		    function(data)
			{
				var item_count = 0;
				$('#basket').html(data);
				activateRemoveLinks(_root);
				animateBasket('delete');
				$('#basket').find('h5').each(function()
				{
					var item = $(this).find('strong').html().split(" ");
						item = parseInt(item[0]);
						
					item_count += item;
				});
				if(item_count == 1)
				{
					$('span.mini_basket_items').html(item_count+' item');
				}
				else
				{
					$('span.mini_basket_items').html(item_count+' items');
				}
			});
		    
		    return false;
		}
	});
	
	$('a.checkoutDelete').click(function()
	{
	    $.get(_root+'basket/',
	    {
			removeCheckoutItem : $(this).attr('id').substring(10),
			ajax               : 'true'
	    },
	    function(data){ $('div#ajaxify').html(data); activateRemoveLinks(_root); });
	    
	    return false;
	});
	
	$('a#empty_basket').click(function()
	{
		$.post(_root+'basket/',
		{
			emptyBasket  : 'true',
			ajax         : 'true'
		},
		function(data)
		{
			$('#basket').html(data);
			activateRemoveLinks(_root);
			activateAddLinks(_root);
			activateProductConfigurators(_root);
			$('span.mini_basket_items').html('0 items');
		});
		
		return false;
	});
}
function activateAddLinks(_root)
{
	$('form.add_to_basket').unbind('submit').bind('submit',function()
	{
	    var containerID = $(this).find('ol[id^="ajaxify-"]').attr('id');
	    
	    var notCompleted = false;
	    
	    $('#'+containerID).find('select').each(function()
	    {
			if(!$(this).attr('value')) { notCompleted = $(this).prev().text(); return false; }
	    });
	    
	    if(notCompleted) // Not all options have been selected as required
	    {
			alert('Please make your '+notCompleted+' selection!');
	    }
	    else // All is gravy...// ONLY PROBLEM BEING THAT ONLY USERS WITH JAVASCRIPT ENABLED WILL SEE AN ERROR
	    {
			var quantity = 1;
			
			if($(this).find('select[name=quantity]').length)
			{
				if($(this).find('select[name=quantity]').val() != '')
				{
					quantity = $(this).find('select[name=quantity]').val();
				}
			}
			
			$.post(_root+'basket/',
			{
		        addToBasket  : 'addToBasket',
		        ajax         : 'true',
		        comboID      : $(this).find('input[name=comboID]').val(),
		        productID    : $(this).find('input[name=productID]').val(),
		        quantity     : quantity
			},
			function(data)
			{
				var item_count = 0;
				$('#basket').html(data);
				activateRemoveLinks(_root);
				animateBasket('add');
				$('#basket').find('h5').each(function()
				{
					var item = $(this).find('strong').html().split(" ");
						item = parseInt(item[0]);
						
					item_count += item;
				});
				if(item_count == 1)
				{
					$('span.mini_basket_items').html(item_count+' item');
				}
				else
				{
					$('span.mini_basket_items').html(item_count+' items');
				}
			});
	    }
	    return false;
	});
}
function activateProductConfigurators(_root)
{
	$('form ol[id^="ajaxify-"] li select').change(function()
	{
	    var containerID = $(this).parent().parent().attr('id');
	    var productID   = $('#'+containerID).parent().next('fieldset').find('input[name=productID]').val();
	    
	    if(typeof(productID) == 'undefined') // Trade Discount Occurence...
	    {
			productID = $('#'+containerID).parent().parent().children('fieldset').eq(2).find('input[name=productID]').val();
	    }
	    
	    var configValues = '';
	    
	    $('#'+containerID).find('select').each(function()
	    {
			if($(this).attr('value') == '')
			{
				configValues += $(this).attr('name')+'===='+'undefined'+';;;;';
			}
			else
			{
				configValues += $(this).attr('name')+'===='+$(this).attr('value')+';;;;';
			}
	    });
	    
	    if($('select#quantity').length) // If Multiple Discount Select Is Present, Reset It
	    {
			$('select#quantity')[0].selectedIndex = 0;
	    }
	    
	    $.post(_root+'reconfigure/',
	    {
			reconfigureProduct : 'reconfigureProduct',
			ajax               : 'true',
			configValues       : configValues,
			productID          : productID
	    },
	    function(data){ $('#'+containerID).html(data); activateProductConfigurators(_root); checkForPriceUpdate(productID); });
	});
	
	$('select#quantity').change(function()
	{
	    var multiple  = $(this).attr('value');
	    var productID = $(this).parent().parent().parent().next('fieldset').find('input[name=productID]').val();
	    
	    if($('input[name="updatedPrice-'+productID+'"]').length)
	    {
			var price = $('input[name="updatedPrice-'+productID+'"]').attr('value');
	    }
	    else
	    {
			var price = $(this).parent().parent().parent().next('fieldset').find('input[name=price]').val();
	    }
	    
	    if(typeof(multiple) != 'undefined' && multiple != '')
	    {
			var discountText  = $(this).find('option:selected').text();
			var discount      = discountText.split(' ');
			
			if(discount[2].indexOf('%') != -1) // Percentage Discount
			{
		        discount = discount[2].slice(0,(discount[2].length-1));
		        
		        if(discount.length == 1)
		        {
		          discount = '0.0'+discount;
		        }
		        else
		        {
		          discount = '0.'+discount;
		        }
				
		        discount = Math.round((price * discount)*100)/100;
				discount = discount * multiple;
			}
			else // Monetary Discount
			{
				discount = discount[2].slice(1);
			}
			
			var multiplePrice = price * multiple;
			multiplePrice = Math.round((multiplePrice - discount)*100)/100;
			
			$('#Price-'+productID).html(CURRENCY+multiplePrice.toFixed(2));
	    }
	    else
	    {
			$('#Price-'+productID).html(CURRENCY+price);
	    }
	});
}
function checkForPriceUpdate(id)
{
	if($('input[name="updatedPrice-'+id+'"]').length)
	{
		$('#Price-'+id).html(CURRENCY+$('input[name="updatedPrice-'+id+'"]').attr('value'));
	}
}

/*
 * jQuery Plugin highlightFade(jquery.offput.ca/highlightFade)
 *(c) 2006 Blair Mitchelmore(offput.ca) blair@offput.ca
 */
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}('6.1D.f=q(B){k o=(B&&B.C==1E)?{u:B}:B||{};k d=6.f.N;k i=o[\'z\']||d[\'z\'];k a=o[\'A\']||d[\'A\'];k H={\'18\':q(s,e,t,c){5 p(s+(c/t)*(e-s))},\'1Q\':q(s,e,t,c){5 p(s+P.1R(((c/t)*1T)*(P.1M/1L))*(e-s))},\'1K\':q(s,e,t,c){5 p(s+(P.1U(c/t,2))*(e-s))}};k t=(o[\'v\']&&o[\'v\'].C==W)?o[\'v\']:H[o[\'v\']]||H[d[\'v\']]||H[\'18\'];h(d[\'v\']&&d[\'v\'].C==W)t=d[\'v\'];5 l.1a(q(){h(!l.4)l.4={};k e=(l.4[a])?l.4[a].n:6.f.Z(l,a)||[7,7,7];k c=6.f.J(o[\'u\']||o[\'1I\']||o[\'1k\']||d[\'u\']||[7,7,m]);k s=6.I(o[\'I\']||d[\'I\']);k r=o[\'Q\']||(l.4[a]&&l.4[a].L)?l.4[a].L:6.1e(l,a);h(o[\'n\']||d[\'n\'])r=6.f.T(e=6.f.J(o[\'n\']||d[\'n\']));h(1d o[\'Q\']!=\'16\')r=o[\'Q\'];h(l.4[a]&&l.4[a].K)X.17(l.4[a].K);l.4[a]={E:((s.1c)/i),z:i,D:0,u:c,n:e,L:r,A:a};6.f(l,a,o[\'1b\'],t)})};6.f=q(e,a,o,t){e.4[a].K=X.1f(q(){k 15=t(e.4[a].u[0],e.4[a].n[0],e.4[a].E,e.4[a].D);k 14=t(e.4[a].u[1],e.4[a].n[1],e.4[a].E,e.4[a].D);k 13=t(e.4[a].u[2],e.4[a].n[2],e.4[a].E,e.4[a].D);6(e).M(a,6.f.T([15,14,13]));h(e.4[a].D++>=e.4[a].E){6(e).M(a,e.4[a].L||\'\');X.17(e.4[a].K);e.4[a]=V;h(o&&o.C==W)o.1l(e)}},e.4[a].z)};6.f.N={u:[7,7,m],z:1j,I:1h,A:\'Y\'};6.f.J=q(c,d){k 8;h(c&&c.C==1g&&c.1i==3)5 c;h(8=/O\\(\\s*([0-9]{1,3})\\s*,\\s*([0-9]{1,3})\\s*,\\s*([0-9]{1,3})\\s*\\)/.F(c))5[p(8[1]),p(8[2]),p(8[3])];G h(8=/O\\(\\s*([0-9]+(?:\\.[0-9]+)?)\\%\\s*,\\s*([0-9]+(?:\\.[0-9]+)?)\\%\\s*,\\s*([0-9]+(?:\\.[0-9]+)?)\\%\\s*\\)/.F(c))5[U(8[1])*2.S,U(8[2])*2.S,U(8[3])*2.S];G h(8=/#([a-x-w-9]{2})([a-x-w-9]{2})([a-x-w-9]{2})/.F(c))5[p("y"+8[1]),p("y"+8[2]),p("y"+8[3])];G h(8=/#([a-x-w-9])([a-x-w-9])([a-x-w-9])/.F(c))5[p("y"+8[1]+8[1]),p("y"+8[2]+8[2]),p("y"+8[3]+8[3])];G 5 6.f.12(c)||d||V};6.f.T=q(a){5"O("+a.1J(",")+")"};6.f.Z=q(e,a,b){k s,t;b=b||19;t=a=a||6.f.N[\'A\'];1m{s=6(e).M(t||\'Y\');h((s!=\'\'&&s!=\'10\')||(e.1F.11()=="1G")||(!b&&e.4&&e.4[a]&&e.4[a].n))1H;t=19}1N(e=e.1S);h(!b&&e.4&&e.4[a]&&e.4[a].n)s=e.4[a].n;h(s==16||s==\'\'||s==\'10\')s=[7,7,7];5 6.f.J(s)};6.f.12=q(c){h(!c)5 V;1O(c.1P(/^\\s*|\\s*$/g,\'\').11()){j\'1s\':5[0,7,7];j\'1t\':5[0,0,0];j\'1r\':5[0,0,7];j\'1q\':5[7,0,7];j\'1n\':5[m,m,m];j\'1o\':5[0,m,0];j\'1p\':5[0,7,0];j\'1u\':5[m,0,0];j\'1v\':5[0,0,m];j\'1B\':5[m,m,0];j\'1C\':5[m,0,m];j\'1A\':5[7,0,0];j\'1z\':5[R,R,R];j\'1w\':5[0,m,m];j\'1x\':5[7,7,7];j\'1y\':5[7,7,0]}};',62,119,'||||highlighting|return|jQuery|255|result|||||||highlightFade||if||case|var|this|128|end||parseInt|function||||start|iterator|F0|fA|0x|interval|attr|settings|constructor|currentStep|steps|exec|else|ts|speed|getRGB|timer|orig|css|defaults|rgb|Math|final|192|55|asRGBString|parseFloat|null|Function|window|backgroundColor|getBaseValue|transparent|toLowerCase|checkColorName|newB|newG|newR|undefined|clearInterval|linear|false|each|complete|duration|typeof|curCSS|setInterval|Array|400|length|50|color|call|do|gray|green|lime|fuchsia|blue|aqua|black|maroon|navy|teal|white|yellow|silver|red|olive|purple|fn|String|tagName|body|break|colour|join|exponential|180|PI|while|switch|replace|sinusoidal|sin|parentNode|90|pow'.split('|'),0,{}))

function enableLightboxes(_root)
{
	if($('a[rel="lightbox"]').length > 0)
	{
		$('a[rel="lightbox"]').lightBox(
		{
			overlayBgColor		: '#000',
			overlayOpacity		: 0.8,
			imageLoading		: _root+'media/images/lightbox-ico-loading.gif',
			imageBtnClose		: _root+'media/images/lightbox-btn-close.gif',
			imageBtnPrev		: _root+'media/images/lightbox-btn-prev.gif',
			imageBtnNext		: _root+'media/images/lightbox-btn-next.gif',
			imageBlank			: _root+'media/images/lightbox-blank.gif',
			containerResizeSpeed: 350,
			txtImage			: 'Image',
			txtOf				: 'of'
		});
		
		addMagnifyingGlass(_root);
	}
	
	$('dl.productImages dt a[rel="productGallery"]').click(function()
	{
		$('a[rel="lightbox"]:first').trigger('click');
		return false;
	});
}

function addMagnifyingGlass(_root)
{
	$('dl.productImages dt a img').after('<img class="superimpose" src="'+_root+'media/images/magnifying-glass.gif" alt="Enlarge Image" />');
}
function removeMagnifyingGlass()
{
	$('img.superimpose').remove();
}

function createHelpTips()
{
	$('div.helpTip').each(function()
	{
		$(this).before('<span class="helpTipReveal">?</span>');
	});
}

function activateHelpTips()
{
	$('span.helpTipReveal').bind(
		'mouseover',function()
		{
			$('div#'+$(this).next().attr("id")).show();
		}
	).bind(
		'mouseout',function()
		{
			$('div#'+$(this).next().attr("id")).hide();
		}
	);
}

function activateQuickFind(_root)
{
	$('form[id="filter"] select').change(function()
	{
	    if($(this).attr('name') != 'orderBy') // Ignore change of order by select
	    {
			var postValue = '';
			
			$('div[id="quickFind_container"]').find('select').each(function()
			{
				postValue += $(this).attr('name')+'='+$(this).attr('value')+';';
			});
			
			$.post(_root+'quickfind/',
			{
				quickFind   : 'quickFind',
				postValue   : postValue
			},
			function(data) { $('div[id="quickFind_container"]').html(data); activateQuickFind(_root) });
	    }
	});
}

function changeNav(id,src)
{
	$('img#'+id).attr("src",_root+"media/images/nav/"+src);
}

/* 
 * CAROUSEL
 * 
 * Based upon:
 * jQuery Coda-Slider v1.1 - http://www.ndoherty.com/coda-slider
 * Copyright(c) 2007 Niall Doherty
 */
$.fn.carousel = function(settings)
{
	return this.each(function()
	{
	    var container = $(this);
	    
		var cslide = 1;
	    
	    container.each(function(i)
	    {
			$("li#feature1 a").click(function(){skipTo('1','true');return false;});
			$("li#feature2 a").click(function(){skipTo('2','true');return false;});
			$("li#feature3 a").click(function(){skipTo('3','true');return false;});
			$("li#feature4 a").click(function(){skipTo('4','true');return false;});
			$("li#feature5 a").click(function(){skipTo('5','true');return false;});
			
			function auto_slide()
			{
				if(!$('div#carousel').find('ul.control li a').hasClass('clicked'))
				{
					if($('li#feature1 a').hasClass('active') && $('li#feature2').length)
					{
						var next_slide = '2';
					}
					else if($('li#feature2 a').hasClass('active') && $('li#feature3').length)
					{
						var next_slide = '3';
					}
					else if($('li#feature3 a').hasClass('active') && $('li#feature4').length)
					{
						var next_slide = '4';
					}
					else if($('li#feature4 a').hasClass('active') && $('li#feature5').length)
					{
						var next_slide = '5';
					}
					else
					{
						var next_slide = '1';
					}
					setTimeout(function()
					{
						skipTo(next_slide,'false');
						auto_slide();
					},4500);
				}
			}
			
			if($('li#feature2').length)
			{
				auto_slide();
			}
			else
			{
				$('ul.control').css('display','none');
			}
			
			function skipTo(slide,click)
			{
				if(click == 'true' || !$('div#carousel').find('ul.control li a').hasClass('clicked'))
				{
					//var cnt = -(slideHeight*(slide-1));
			        
					//$("ul.carousel").animate({ marginTop: cnt+"px" }, 750);
					
					$('li#feature1 a').removeClass('active');
			        $('li#feature2 a').removeClass('active');
			        $('li#feature3 a').removeClass('active');
			        $('li#feature4 a').removeClass('active');
			        $('li#feature5 a').removeClass('active');
			        
			        switch(slide)
			        {
			          case '1':
			            $('li#feature1 a').addClass('active');
						$('li.feature1').addClass('current');
						
						if($('li.feature2').hasClass('current'))
						{
							$('li.feature1').fadeIn('fast', function() { $('li.feature2').fadeOut('slow'); });
						}
						else if($('li.feature3').hasClass('current'))
						{
							$('li.feature1').fadeIn('fast', function() { $('li.feature3').fadeOut('slow'); });
						}
						else if($('li.feature4').hasClass('current'))
						{
							$('li.feature1').fadeIn('fast', function() { $('li.feature4').fadeOut('slow'); });
						}
						else if($('li.feature5').hasClass('current'))
						{
							$('li.feature1').fadeIn('fast', function() { $('li.feature5').fadeOut('slow'); });
						}
						
						$('li.feature2').removeClass('current');
						$('li.feature3').removeClass('current');
						$('li.feature4').removeClass('current');
						$('li.feature5').removeClass('current');
						
						if(click == 'true')
						{
							$('li#feature1 a').addClass('clicked');
						}
						
			            break;
						
			          case '2':
						
						if($('li.feature1').hasClass('current'))
						{
							$('li.feature2').fadeIn('slow', function() { $('li.feature1').fadeOut('slow'); });
						}
						else if($('li.feature3').hasClass('current'))
						{
							$('li.feature2').fadeIn('slow', function() { $('li.feature3').fadeOut('slow'); });
						}
						else if($('li.feature4').hasClass('current'))
						{
							$('li.feature2').fadeIn('slow', function() { $('li.feature4').fadeOut('slow'); });
						}
						else if($('li.feature5').hasClass('current'))
						{
							$('li.feature2').fadeIn('slow', function() { $('li.feature5').fadeOut('slow'); });
						}
						
			            $('li#feature2 a').addClass('active');
						$('li.feature2').addClass('current');
						
						$('li.feature1').removeClass('current');
						$('li.feature3').removeClass('current');
						$('li.feature4').removeClass('current');
						$('li.feature5').removeClass('current');
						
						if(click == 'true')
						{
							$('li#feature2 a').addClass('clicked');
						}
						
			            break;
						
			          case '3':
						
						if($('li.feature1').hasClass('current'))
						{
							$('li.feature3').fadeIn('slow', function() { $('li.feature1').fadeOut('slow'); });
						}
						else if($('li.feature2').hasClass('current'))
						{
							$('li.feature3').fadeIn('slow', function() { $('li.feature2').fadeOut('slow'); });
						}
						else if($('li.feature4').hasClass('current'))
						{
							$('li.feature3').fadeIn('slow', function() { $('li.feature4').fadeOut('slow'); });
						}
						else if($('li.feature5').hasClass('current'))
						{
							$('li.feature3').fadeIn('slow', function() { $('li.feature5').fadeOut('slow'); });
						}
						
			            $('li#feature3 a').addClass('active');
						$('li.feature3').addClass('current');
						
						$('li.feature1').removeClass('current');
						$('li.feature2').removeClass('current');
						$('li.feature4').removeClass('current');
						$('li.feature5').removeClass('current');
						
						if(click == 'true')
						{
							$('li#feature3 a').addClass('clicked');
						}
			            break;
						
			          case '4':
						
						if($('li.feature1').hasClass('current'))
						{
							$('li.feature4').fadeIn('slow', function() { $('li.feature1').fadeOut('slow'); });
						}
						else if($('li.feature2').hasClass('current'))
						{
							$('li.feature4').fadeIn('slow', function() { $('li.feature2').fadeOut('slow'); });
						}
						else if($('li.feature3').hasClass('current'))
						{
							$('li.feature4').fadeIn('slow', function() { $('li.feature3').fadeOut('slow'); });
						}
						else if($('li.feature5').hasClass('current'))
						{
							$('li.feature4').fadeIn('slow', function() { $('li.feature5').fadeOut('slow'); });
						}
						
			            $('li#feature4 a').addClass('active');
						$('li.feature4').addClass('current');
						
						$('li.feature1').removeClass('current');
						$('li.feature2').removeClass('current');
						$('li.feature3').removeClass('current');
						$('li.feature5').removeClass('current');
						
						if(click == 'true')
						{
							$('li#feature4 a').addClass('clicked');
						}
			            break;
						
			          case '5':
						
						if($('li.feature1').hasClass('current'))
						{
							$('li.feature5').fadeIn('slow', function() { $('li.feature1').fadeOut('slow'); });
						}
						else if($('li.feature2').hasClass('current'))
						{
							$('li.feature5').fadeIn('slow', function() { $('li.feature2').fadeOut('slow'); });
						}
						else if($('li.feature3').hasClass('current'))
						{
							$('li.feature5').fadeIn('slow', function() { $('li.feature3').fadeOut('slow'); });
						}
						else if($('li.feature4').hasClass('current'))
						{
							$('li.feature5').fadeIn('slow', function() { $('li.feature4').fadeOut('slow'); });
						}
						
			            $('li#feature5 a').addClass('active');
						$('li.feature5').addClass('current');
						
						$('li.feature1').removeClass('current');
						$('li.feature2').removeClass('current');
						$('li.feature3').removeClass('current');
						$('li.feature4').removeClass('current');
						
						if(click == 'true')
						{
							$('li#feature5 a').addClass('clicked');
						}
			            break;
			        }
				}
			}
	    });
	});
};