/*	
	Format the site search
*/
document.write("<style type='text/css'>");
document.write("#login");
document.write("{");
document.write("display: none;");
document.write("}");
document.write("</style>");

function jqPngFix() {
    try {
        //ie6 png transperency fix
        $.each($("img[src$=.png],img[src$=.PNG]"), function () {
            var img = $(this);
            img.css({"width": img.width(),"height": img.height(), "filter": "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + img.attr("src") + "', sizingMethod='scale')"});
            img.attr("src","/templates/images/construct/blank.gif");
        });
    } catch(e) {
        alert(e.description)
    }
}
jQuery.noConflict();
jQuery(document).ready(function(){

	if (jQuery.browser.msie && jQuery.browser.version == '6.0') {
		jqPngFix();
	}
	
	//New window
	jQuery('a.activeLink').click(function(){
	    window.open(this.href,'','fullscreen=yes, scrollbars=auto');
	    return false;
	});
	
	//New window
	jQuery('a.newWin').click(function(){
	    window.open(this.href,'');
	    return false;
	});
	
	//Bookmark
	jQuery("a.jQueryBookmark").click(function(e){
		e.preventDefault(); // this will prevent the anchor tag from going the user off to the link
		var bookmarkUrl = this.href;
		var bookmarkTitle = this.title;
	 
		if (window.sidebar) { // For Mozilla Firefox Bookmark
			window.sidebar.addPanel(bookmarkTitle, bookmarkUrl,"");
		} else if( window.external || document.all) { // For IE Favorite
			window.external.AddFavorite( bookmarkUrl, bookmarkTitle);
		} else if(window.opera) { // For Opera Browsers
			jQuery("a.jQueryBookmark").attr("href",bookmarkUrl);
			jQuery("a.jQueryBookmark").attr("title",bookmarkTitle);
			jQuery("a.jQueryBookmark").attr("rel","sidebar");
		} else { // for other browsers which does not support
			 alert('Your browser does not support this bookmark action');
			 return false;
		}
	});



	jQuery("#login form").css({"position":"absolute","width":"420px","right":"-424px","float":"left","padding-top":"10px","padding-left":"200px","margin-left":"10px"});
	jQuery("#login.error form").css({"right":"0"});
	jQuery("#login.error h2").hide();
	jQuery("#login.error h2").addClass("tabbed");
	jQuery("#login").prepend("<p id=\"tooltipLogin\">Click here to log into the <strong>1-1 service</strong> &gt;</p>");
	jQuery("#tooltipLogin").hide();
	jQuery("#login h2").addClass("tabbed").click(function() {
		jQuery("#tooltipLogin").fadeOut();
		jQuery(this).fadeOut();
		jQuery("#login form").fadeIn(300);
		jQuery("#login form").animate({ "right":"0" }, {queue:false, duration:300});
		return false;
	});
	jQuery(".tabbed").hover(function() {
		jQuery("#tooltipLogin").fadeIn();
	}, function() {
		jQuery("#tooltipLogin").fadeOut();
	});
	jQuery("#login form ul").append("<li id=\"cancelLogin\"> / <a href=\"#\">Cancel sign-in</a></li><li> / <a href=\"forgotten-password.html\">Forgotten password</a></li>\n");
	jQuery("#cancelLogin").click(function() {
		jQuery("#login h2").fadeIn();
		jQuery("#login form").fadeOut(300);
		jQuery("#login form").animate({ "right":"-424px" }, {queue:false, duration:300});
		return false;
	});
	
	$labelText = jQuery("#siteSearch label").html();
	jQuery("#keywords").attr("value",$labelText);
	jQuery("#siteSearch label").hide();
	jQuery("#keywords").focus(function() {
		if (jQuery(this).attr("value") == $labelText) {
			jQuery(this).attr("value","");
		}
	});
	jQuery("#keywords").blur(function() {
		if (!jQuery(this).attr("value")) {
			jQuery(this).attr("value",$labelText);
		}
	});
	
	$labelUser = jQuery("#login-username").prev("label").html();
	$labelPass = jQuery("#login-password").prev("label").html();
	jQuery("#clientLogin label").hide();
	jQuery("#clientLogin .formRow input:password").css({display:"none"});
	jQuery("#clientLogin .formRow input:password").after('<input type="text" id="passwordVis" name="passwordVis" value="Password" />');
	jQuery("#passwordVis").focus(function() {
		jQuery(this).css({display:"none"});
		jQuery("#clientLogin .formRow input:password").css({display:"block"}).focus();
		jQuery("#clientLogin .formRow input:password").addClass("focussed");
	});
	jQuery("#clientLogin .formRow input:password").focus(function() {
		jQuery(this).addClass("focussed");
	});
	jQuery("#clientLogin .formRow input:password").blur(function() {
		if (!jQuery(this).attr("value")) {
			jQuery(this).css({display:"none"});
			jQuery("#passwordVis").css({display:"block"});
		}
		jQuery(this).removeClass("focussed");
	});
	jQuery("#login-username").focus(function() {
		if (jQuery(this).attr("value") == $labelUser) {
			jQuery(this).attr("value","");
		}
		jQuery(this).addClass("focussed");
	});
	jQuery("#login-username").blur(function() {
		if (!jQuery(this).attr("value")) {
			jQuery(this).attr("value",$labelUser);
		}
		jQuery(this).removeClass("focussed");
	});
	jQuery("#login:not(.error) form").hide();
	jQuery("#login").css({"display":"block"});
jQuery(".auxContent #optSelects div").hide();
	jQuery(".auxContent #optSelects").append('<p><a href="#" id="optSelectsReveal" class="showOpt">More Options&hellip;</a></p>');
	
	jQuery(".auxContent #optSelectsReveal").click(function() {
		if (jQuery(this).attr("class") == "showOpt") {
			jQuery(this).html("Less Options&hellip;");
			jQuery("#optSelects div").slideDown();
			jQuery(this).attr("class", "hideOpt");
		} else {
			jQuery(this).html("More Options&hellip;");
			jQuery("#optSelects div").slideUp();
			jQuery(this).attr("class", "showOpt");
		}
		return false;
	});
jQuery("#ctrl_filter_search").attr('value','Search our products');
	jQuery("#ctrl_filter_search").focus(function() {
		if (jQuery(this).attr("value") == "Search our products") {
			jQuery(this).attr("value","");
		}
		jQuery(this).addClass("focussed");
	});
	jQuery("#ctrl_filter_search").blur(function() {
		if (!jQuery(this).attr("value")) {
			jQuery(this).attr("value","Search our products");
		}
		jQuery(this).removeClass("focussed");
	});
	
	jQuery('#tl_products_search label').hide();
	jQuery('#tl_products_search').css('bottom','5px').hide();
	jQuery('#printLogo').after('<div class="radios"><input type="radio" name="searches" value="site" id="siteRadio" checked="checked" /><label for="siteRadio">Search site</label><input type="radio" name="searches" value="product" id="productRadio" /><label for="productRadio">Search products</label></div>');

	jQuery("input[name='searches']").change(

		function()
		{
			
			if (jQuery("input[name='searches']:checked").val() == "site") {
				jQuery('#tl_products_search').hide();
				jQuery('#siteSearch').show();
			} else {
				jQuery('#tl_products_search').show();
				jQuery('#siteSearch').hide();
			}
			jQuery(this).blur();
		}
	
	);
	if (jQuery('.mainContent #ctrl_filter_field_division').length > 0) {
		jQuery('#productRadio').click().blur();
		jQuery('#tl_products_search').show();
		jQuery('#siteSearch').hide();
	}
	
});
