function autoFill(id, v){
	$(id).css({ color: "#000" }).attr({ value: v }).focus(function(){
		if($(this).val()==v){
			$(this).val("").css({ color: "#000" });
		}
	}).blur(function(){
		if($(this).val()==""){
			$(this).css({ color: "#000" }).val(v);
		}
	});
}

$(document).ready(function() {
	autoFill($("#looking_for"), "Name");	
	autoFill($("#email"), "Email");
	autoFill($("#company"), "Company");	
	autoFill($("#tel"), "Telephone");	
	autoFill($("#comments"), "I'm looking for....");
	autoFill($("#search_reference"), "Search by Catalogue Ref");
	autoFill($("#search_keyword"), "Search by Keyword");
	
	autoFill($("#ctl00_topsearch_keyword"), "Item Search");
	autoFill($("#topsearch_keyword"), "Item Search");	
	autoFill($("#name"), "Name");
	autoFill($("#qty"), "Qty");
	autoFill($("#qty1"), "Qty1");
	autoFill($("#qty2"), "Qty2");
	autoFill($("#qty3"), "Qty3");

	/*Skin Quick Quote*/
	autoFill($(".QQname"), "Name");
	autoFill($(".QQcompany"), "Company");
	autoFill($(".QQemail"), "Email");
	autoFill($(".QQtel"), "Telephone");
	autoFill($(".QQqty"), "Qty");

	autoFill($(".search_keyword"), "Search by Keyword");

	/*Ideas List form*/
	autoFill($(".ILFromName"), "Your Name (*)");
	autoFill($(".ILFromCompName"), "Your Company Name (*)");
	autoFill($(".ILFromEmail"), "Your Email (*)");
	autoFill($(".ILToCompName"), "Recipient: Company Name (*)");
	autoFill($(".ILToName"), "Recipient: Name (*)");
	autoFill($(".ILToEmail"), "Recipient: Email (*)");
	autoFill($(".ILToCCEmail"), "Recipient CC: Email Address");
	autoFill($(".ILToMessage"), "Your Message (*)");

	autoFill($(".homeQEName"), "Name");
	autoFill($(".homeQEEmail"), "Email");
	autoFill($(".homeQECompany"), "Company");
	autoFill($(".homeQETel"), "Telephone");
	autoFill($(".homeQEComments"), "I'm looking for....");
});


/* Scheme Site Functions 
---------------------------*/

$(function() {

	$("label:has(:text) :text").each(function() {
		var $this = $(this);
		if ($this.val() != "") {
			$this.parent().addClass("hide")
		}
	});

	$("#search input, #quick-enquiry input, #quick-enquiry textarea, .text").bind("click", function() {

		var id = $(this).attr("id");
		$("[for='" + id + "']").addClass('hide');

		$(this).bind("blur", function() {
			if ($(this).val() == "") $("[for='" + id + "']").removeClass('hide');
		});
	});
	if ($("#search input").val() == "") {
		hidelabel($(this));
	}
	if ($("#quick-enquiry input").val() == "") {
		hidelabel($(this));
	}
	if ($("#quick-enquiry textarea").val() == "") {
		hidelabel($(this));
	}

	var timer, hidepanel = function() {
		$("#navigation a.active").removeClass("active");
		$(".nav-panel").hide().parent().hide();
		$("#flash").css("visibility", "visible");
	};

	if ($("#ctl00_ContentPlaceHolder1_SearchBy_txtKeywordSearch").val() != "") {
		$(this).prev().hide();
	}
	/*
	$("#ctl00_ContentPlaceHolder1_SearchBy_txtKeywordSearch").bind("keydown", function(e) {
	var $this = $(this);
	if($this != "" && e.keyCode == 13) {
	$("form:eq(0)").submit();
	$this.prev().hide();
	}
		
	});
	*/
	$("#navigation a").hover(function() {
		clearTimeout(timer);
		$(".nav-panel").hide();
		$("#navigation a.active").removeClass("active");

		var $this = $(this).addClass("active");
		var rel = $this.attr("rel");

		$("#flash").css("visibility", "hidden");
		$("#" + rel).show().parent().show();

	}, function() {

		timer = setTimeout(hidepanel, 500);
	});

	$("#masthead").bind("mouseover", function() {
		hidepanel();
	});

	$(".nav-panel").hover(function() {
		clearTimeout(timer);
	}, function() {
		hidepanel();
	});

	$("#tabs a").click(function(e) {
		var $this = $(this);
		var index = $("#tabs a").removeClass("active").index(this);

		e.preventDefault();
		$this.addClass("active");
		$(".feat .row").hide().eq(index).show();
	});

	$(".new").click(function() {
		var href = $(this).next().find("a").attr("href");
		window.location = href;
	});

	$("#bookmark").click(function(e) {
		e.preventDefault();
		title = document.title;
		url = window.location.href;

		if (window.sidebar) { // Mozilla Firefox Bookmark
			window.sidebar.addPanel(title, url, "");
		} else if (window.external) { // IE Favorite
			window.external.AddFavorite(url, title);
		}
		else {
			alert("Please press ctrl + D/cmd + D to bookmark this page!");
		}
	});

	// Basket modal
	$modal = $("#mdlPopup");
	modalH = $modal.outerHeight();
	modalW = $modal.outerWidth();
	windowH = $(window).height();
	windowW = $(window).width();
	$modal.before("<div id=\"overlay\"><!--[if lte IE 6]><iframe></iframe><![endif]--></div>");
	$overlay = $("#overlay").css({ height: $(document).height(), opacity: "0.6" });

	// Info modal
	$infomodal = $("#infomdlPopup");
	infomodalH = $infomodal.outerHeight();
	infomodalW = $infomodal.outerWidth();
	windowH = $(window).height();
	windowW = $(window).width();
	$infomodal.before("<div id=\"overlay\"><!--[if lte IE 6]><iframe></iframe><![endif]--></div>");

});

var flashvars = {};
var params = {
	menu: "false"
};
var attributes = {
	id: "flash",
	name: "flash"
};

//$(document).ready(function() {
//	Cufon.replace('h2,h3,#welcome p,.search-result #content h2');
//
//});


// Basket modal
basketModal = function(text) {
	modalH = $modal.outerHeight();
	modalW = $modal.outerWidth();
	windowH = $(window).height();
	windowW = $(window).width();
	if (text) $modal.find("p").html(text);
	var left = (windowW / 2) - (modalW / 2);
	var top = ((windowH / 2) + $(window).scrollTop()) - (modalH / 2) - 22;
	$overlay.fadeIn(500);
	$("#overlay iframe").css({ top: top, left: left, width: $modal.outerWidth(), height: $modal.outerHeight() })

	$modal
	.css({ top: top, left: left })
	.fadeIn(500)
	.find("img[class='modal-close'], img[class='continue']")
	.click(function(e) {
		e.preventDefault();
		$modal.hide();
		$overlay.fadeOut(750);
	});
}

$(window).resize(function() {
	modalH = $modal.outerHeight();
	modalW = $modal.outerWidth();
	windowH = $(window).height();
	windowW = $(window).width();
	var left = (windowW / 2) - (modalW / 2);
	var top = ((windowH / 2) + $(window).scrollTop()) - (modalH / 2) - 22;
	if ($modal.is(":visible")) {
		$modal.animate({ top: top, left: left }, 500);
	}
});

// Info modal
infoModal = function(text) {
	infomodalH = $infomodal.outerHeight();
	infomodalW = $infomodal.outerWidth();
	windowH = $(window).height();
	windowW = $(window).width();
	if (text) $infomodal.find("p").html(text);
	var left = (windowW / 2) - (modalW / 2);
	var top = ((windowH / 2) + $(window).scrollTop()) - (infomodalH / 2) - 22;
	$overlay.fadeIn(500);
	$("#overlay iframe").css({ top: top, left: left, width: $infomodal.outerWidth(), height: $infomodal.outerHeight() })

	$infomodal
	.css({ top: top, left: left })
	.fadeIn(500)
	.find("img[class='modal-close'], img[class='continue']")
	.click(function(e) {
		e.preventDefault();
		$infomodal.hide();
		$overlay.fadeOut(750);
	});
}
$(window).resize(function() {
	infomodalH = $infomodal.outerHeight();
	infomodalW = $infomodal.outerWidth();
	windowH = $(window).height();
	windowW = $(window).width();
	var left = (windowW / 2) - (infomodalW / 2);
	var top = ((windowH / 2) + $(window).scrollTop()) - (infomodalH / 2) - 22;
	if ($infomodal.is(":visible")) {
		$infomodal.animate({ top: top, left: left }, 500);
	}
});



function echeck(str) {
	var at = "@";
	var dot = ".";
	var lat = str.indexOf(at);
	var lstr = str.length;
	var ldot = str.indexOf(dot);
	var msg = "";
	if (str.indexOf(at) == -1) {
		return false
	}
	if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr) {
		return false
	}
	if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr) {
		return false
	}
	if (str.indexOf(at, (lat + 1)) != -1) {
		return false
	}
	if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot) {
		return false
	}

	if (str.indexOf(dot, (lat + 2)) == -1) {
		return false
	}
	if (str.indexOf(" ") != -1) {
		return false
	}
	return true
}
