//Begin jquery
$(function(){
		   
	//Flame Menu
	$('#FlameMenu li:last-child').addClass('last');
	$('#FlameMenu li:has(ul)').addClass('hasSub');
	$('#FlameMenu .inner > ul').addClass('parent');
	$('#FlameMenu .inner > ul > li > ul').addClass('child');
	$('#FlameMenu .inner > ul > li > ul > li > ul').addClass('grandchild');
	$('#FlameMenu ul.flamemenu.parent').find('> li').addClass(function(index) {return 'i' + index;});
	$('<li class="Break">').insertAfter('#FlameMenu .flamemenu .child li:nth-child(3n)');
	
	$('.flamemenu').prepend('<li class="home"><a href="/"><img src="/templates/Electronics/images/magenta/home-icon.png" alt="home"></a></li>');

	$('#FlameMenu ul.child').wrap('<div class="parentwrap">');
	
	$('#FlameMenu li').hover(function(){
		$(this).addClass('active').find('div.parentwrap, div.parentwrap ul').stop(true, true).show();						  							  
	}, function(){
		$(this).removeClass('active').find('div.parentwrap').stop(true, true).hide();	
	});

	//Pages Menu
	$('#Menu li:last-child').addClass('last');
	
	//Side category active category
	var location = $('#CategoryBreadcrumb li:nth-child(3) a').attr('href');
	$('body#catChild .SideCategoryListClassic li a[href=' + location + ']').parents(':eq(1)').addClass('parent').css('display', 'block').find('ul').addClass('child').css('display', 'block');
	
	var locationBase = window.location;
	$('body#catBase .SideCategoryListClassic li a[href=' + locationBase + ']').parents(':eq(1)').css('display', 'block').find('ul').addClass('child').css('display', 'block');
	//Search field
	$('#SearchForm input').focus (function() {
		$('#SearchForm').addClass('active');
		$('#SearchForm input.Button').attr("src", "/templates/Electronics/images/magenta/SearchActive.gif");
	});
	
	$('#SearchForm input').blur(function() {
		$('#SearchForm').removeClass('active');
		$('#SearchForm input.Button').attr("src", "/templates/Electronics/images/magenta/Search.gif");
	});
	
	$('#SideSearch input').focus (function() {
		$('#SideSearch').addClass('active');
		$('#SideSearch input.Button').attr("src", "/templates/Electronics/images/magenta/SearchActive.gif");
	});
	
	$('#SideSearch input').blur(function() {
		$('#SideSearch').removeClass('active');
		$('#SideSearch input.Button').attr("src", "/templates/Electronics/images/magenta/Search.gif");
	});
	
	//Account box
	var logout = $('#TopMenu div#Message a').attr('href').indexOf("logout");

	if (logout < 0){
		$('#MyAccount').remove();
		$('#TopCartContents').remove();
	} else {
		$('#MyAccount').show();
		$('#TopCartContents').show();
	}
	
	$('#TopMenu #MyAccount span').click(function() {
		$('#TopMenu #MyAccount ul').show();
		$(this).addClass("open");
	});
	
	$(document).mouseup(function(e) {
		if($(e.target).parent("#TopMenu #MyAccount span").length==0) {
			$("#TopMenu #MyAccount span").removeClass("open");
			$("#TopMenu #MyAccount ul").hide();
		}
	}); 
	
	//Home page tabs

	//When page loads...
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content

	//On Click Event
	$("ul.tabs li").click(function() {

		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		return false;

	});
	
	//newsletter
	var name = $('input#nl_first_name').attr('value');

	$('input#nl_first_name').focus (function() {
		$(this).addClass('active');
		if ($(this).attr('value') == name) {
				$(this).val("")
		}
	});
	
	$('input#nl_first_name').blur(function() {
		if ($(this).attr('value') == "") {
				$(this).val(name)
		}
	});
	
	var email = $('input#nl_email').attr('value');

	$('input#nl_email').focus (function() {
		$(this).addClass('active');								
		if ($(this).attr('value') == email) {
				$(this).val("")
		}
	});
	
	$('input#nl_email').blur(function() {
		if ($(this).attr('value') == "") {
				$(this).val(email)
		}
	});
	
	//Make li's clickable
	$("#HomeContent #Primary #SmallCats ul li").click(function(){
     window.location=$(this).find("a").attr("href");
     return false;
});
	
	//Back to search results
	var refsearch = referrer.indexOf("search");
	
	if (refsearch > 0){
		$(function(){
			$('#Back span.search').css('display', 'inline-block');
		});
	}else{
		$('#Back span.back').css('display', 'inline-block');
		}
		
	//Sub category
	$('.SubCategoryListGrid li:nth-child(4n+3)').css('margin-right', '0px');
	$('.SubCategoryListGrid li:last-child').addClass('RowDivider');
	
//End jquery
});


