/**
 * @author neila
 */
$(document).ready(function() {
	/* Round corners */
	$('#nav li.level1').corner("notch 2px");
	$('p.shop_button').corner('');

	/* IE6 Transparancies */
	if(browser_is_ie6()) {
		$('#header').supersleight();
		$('.item_holder,.main_product,.product_holder,.cart_item').supersleight();
	}
	
});

function check_account(source)
{
	if(source.val().length > 5 && $("#email_login_prompt").attr('id')) {
	
		$.get("ajax/",{
		"page":"login",
	 	"action": "check_account",
	 	"email": source.val()
	 	},
	 	function(response) {
			
			if(response == 1) {
				
				$("#email_login_prompt").show();
				
				href = $("#email_login_prompt a.login").attr("href");
				
				split_href = href.split("&");
				
				if(source.attr("id") == "email") {
					redirect="my_account";
				}
				else if(source.attr("id") == "b_email") {
					redirect = "checkout";
				}
				
				split_href[1] = "redirect=" + redirect;
				
				href = split_href.join("&");
				
				$("#email_login_prompt a.login").attr("href",href);

				$('#cart_continue input').attr("disabled","disabled");
			}
			else {

				$("#email_login_prompt").hide();
				$('#cart_continue input').removeAttr("disabled");
			}
		});
	}
	else {
		$("#email_login_prompt").hide();
		$('#cart_continue input').removeAttr("disabled");		
	}
}
function send_new_password(email) {

	$.get("ajax/index.php",{
 		"page": "login",
		"action":"lost_password",
 		"email": email
 	},
	function(response) {
		
		if(response == 1) {
			$("#email_login_prompt").html(
				"<p>A new password has been sent to your email address</p>"+
				"<p>You may now <a href=\"?page=login&redirect=checkout\">Login</a> with your new password</p>"
			);	
		}
	});
}
/* IE6 fix for suckerfish menu */
sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

/*
	Style active nodes for suckerfish
*/
function style_menu(category_id) {
	
	source = $("#node_" + category_id);
	source.addClass('selected');
	source.parents('li').addClass('selected');
}

function browser_is_ie6() {
	
	if(typeof document.body.style.maxHeight === "undefined") {
	        return true;
	} else {
	        return false;
	}
}
