/*------------------------------------------------------------------
[JQuery Basics]
Project:		Funktional Furniture
Version:		1.0
Last change:	22/01/09
-------------------------------------------------------------------*/

function setCookie( name, value, expires)
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + ";path=/";
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1; 
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return "";
}

            
jQuery.noConflict();
var $j = jQuery;
$j(document).ready(function() {
	// Adds hook for Opera
	if($j.browser.opera) {$j("body").addClass("opera");};
	// Assigning _blank to all external links
	$j('a[rel="external"]').attr("target", "_blank");
	//Navigation animation
	var navLinks = $j("#navGlobalContent li a:not('#selected')");
		navLinks.children('em').css({opacity: '0', backgroundPosition: '0px'});
		navLinks.hoverIntent({sensitivity: 3, interval: 1, over:linkOver, timeout: 100, out:linkOut}); 
		function linkOver(){$j(this).children('em').stop().animate({opacity:"1"}, 500, "easeInOutQuad")};
		function linkOut(){ $j(this).children('em').animate({opacity:"0"}, 200, "easeInOutQuad")};
	// Change Focus of text on all inputs
	$j('input.search').focus(function(){
		var defaultText = $j(this).val();
		$j(this).val('');
		$j("input.search").blur( function () {
			var userInput = $j(this).val();
			if (userInput == ""){
				$j(this).val(defaultText);
			}
		});
	});
	// Thumbnail changer
	$j('.productsThumbs .products span').css({opacity: '0', border: '4px solid #ed0677'});
	$j('.productsThumbs .products').hover(function(){$j(this).children('span').stop().animate({opacity: 1},500, "easeInOutQuad");},function(){$j(this).children('span').stop().animate({opacity: 0},500, "easeInOutQuad");});
	// Enter manual address
	$j("#manualAddress").hide();
	$j("a.enterAddress").click(function(){$j(this).parent().next("#manualAddress").slideToggle();return false;});
	// The accordion is not the tidiest but it works.
	// Accordion Globals
	$j(".accordionContent").hide();
	$j('<img src="'+preurl+'/themes/alphaclear/_includes/Images/Global/toggleClose.gif" class="arrow" />').insertAfter('.accordionToggle a');
	// Accordion for sub navigation
	$j("#subNavigation .accordionToggle a").click(function(){
		if ($j(this).is('.active')) {
            setCookie('menuid',"",10);
			$j(this).toggleClass("active");
			$j('#subNavigation .arrow.active').attr('src',''+preurl+'/themes/alphaclear/_includes/Images/Global/toggleClose.gif');
			$j(this).parent().parent().next("#subNavigation .accordionContent").slideToggle();
			return false;
		} else {
            setCookie('menuid',this.id,10);
			$j("#subNavigation .accordionContent:visible").slideUp("slow");
			$j(".accordionToggle a.active").removeClass("active");
			$j(this).toggleClass("active");
			$j('#subNavigation .arrow.active').attr('src',''+preurl+'/themes/alphaclear/_includes/Images/Global/toggleClose.gif'); // change the image src of the current ACTIVE image to have an INACTIVE state.
			$j("#subNavigation .arrow").addClass('active');
			$j(this).siblings('#subNavigation .arrow.active').attr('src',''+preurl+'/themes/alphaclear/_includes/Images/Global/toggleOpen.gif');
			$j(this).parent().parent().next("#subNavigation .accordionContent").slideToggle();
			return false;
		}
	});
	// Accordion for product information
	$j("#productInformation .accordionToggle a").click(function(){
		if ($j(this).is('.active')) {
			$j(this).toggleClass("active");
			$j('#productInformation .arrow.active').attr('src',''+preurl+'/themes/alphaclear/_includes/Images/Global/toggleClose.gif');
			$j(this).parent().parent().next("#productInformation .accordionContent").slideToggle();
			return false;
		} else {
			$j("#productInformation .accordionContent:visible").slideUp("slow");
			$j("#productInformation .accordionToggle a.active").removeClass("active");
			$j(this).toggleClass("active");
			$j('#productInformation .arrow.active').attr('src',''+preurl+'/themes/alphaclear/_includes/Images/Global/toggleClose.gif'); // change the image src of the current ACTIVE image to have an INACTIVE state.
			$j("#productInformation .arrow").addClass('active');
			$j(this).siblings('#productInformation .arrow.active').attr('src',''+preurl+'/themes/alphaclear/_includes/Images/Global/toggleOpen.gif');
			$j(this).parent().parent().next("#productInformation .accordionContent").slideToggle();
			return false;
		}
	});
    $j("#subNavigation .accordionContent a").click(function(){
        setCookie('menusel',this.getAttribute("href"),10);
    });
    if(getCookie('menuid')!=""){
        var menutop=$j("#subNavigation #"+getCookie('menuid'));
        $j("#subNavigation .accordionContent:visible").slideUp("slow");
        $j(".accordionToggle a.active").removeClass("active");
        menutop.toggleClass("active");
        $j('#subNavigation .arrow.active').attr('src',''+preurl+'/themes/alphaclear/_includes/Images/Global/toggleClose.gif'); // change the image src of the current ACTIVE image to have an INACTIVE state.
        $j("#subNavigation .arrow").addClass('active');
        menutop.siblings('#subNavigation .arrow.active').attr('src',''+preurl+'/themes/alphaclear/_includes/Images/Global/toggleOpen.gif');
        menutop.parent().parent().next("#subNavigation .accordionContent").slideToggle();
    }
	// Alternate Row Colours
	$j("tr:nth-child(even)").addClass("even");
    	
});











