/*	
	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)
    }
}
$(document).ready(function(){
	if ($.browser.msie && $.browser.version == '6.0') {
		jqPngFix();
	}
	
	//New window
	$('a.activeLink').click(function(){
	    window.open(this.href,'','fullscreen=yes, scrollbars=auto');
	    return false;
	});
	
	//New window
	$('a.newWin').click(function(){
	    window.open(this.href,'');
	    return false;
	});
	
	//Bookmark
	$("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
			$("a.jQueryBookmark").attr("href",bookmarkUrl);
			$("a.jQueryBookmark").attr("title",bookmarkTitle);
			$("a.jQueryBookmark").attr("rel","sidebar");
		} else { // for other browsers which does not support
			 alert('Your browser does not support this bookmark action');
			 return false;
		}
	});



	$("#login form").css({"position":"absolute","width":"420px","right":"-424px","float":"left","padding-top":"10px","padding-left":"200px","margin-left":"10px"});
	$("#login.error form").css({"right":"0"});
	$("#login.error h2").hide();
	$("#login.error h2").addClass("tabbed");
	$("#login").prepend("<p id=\"tooltipLogin\">Click here to log into the <strong>1-1 service</strong> &gt;</p>");
	$("#tooltipLogin").hide();
	$("#login h2").addClass("tabbed").click(function() {
		$("#tooltipLogin").fadeOut();
		$(this).fadeOut();
		$("#login form").fadeIn(300);
		$("#login form").animate({ "right":"0" }, {queue:false, duration:300});
		return false;
	});
	$(".tabbed").hover(function() {
		$("#tooltipLogin").fadeIn();
	}, function() {
		$("#tooltipLogin").fadeOut();
	});
	$("#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");
	$("#cancelLogin").click(function() {
		$("#login h2").fadeIn();
		$("#login form").fadeOut(300);
		$("#login form").animate({ "right":"-424px" }, {queue:false, duration:300});
		return false;
	});
	
	$labelText = $("#siteSearch label").html();
	$("#keywords").attr("value",$labelText);
	$("#siteSearch label").hide();
	$("#keywords").focus(function() {
		if ($(this).attr("value") == $labelText) {
			$(this).attr("value","");
		}
	});
	$("#keywords").blur(function() {
		if (!$(this).attr("value")) {
			$(this).attr("value",$labelText);
		}
	});
	
	$labelUser = $("#login-username").prev("label").html();
	$labelPass = $("#login-password").prev("label").html();
	$("#clientLogin label").hide();
	$("#clientLogin .formRow input:password").css({display:"none"});
	$("#clientLogin .formRow input:password").after('<input type="text" id="passwordVis" name="passwordVis" value="Password" />');
	$("#passwordVis").focus(function() {
		$(this).css({display:"none"});
		$("#clientLogin .formRow input:password").css({display:"block"}).focus();
		$("#clientLogin .formRow input:password").addClass("focussed");
	});
	$("#clientLogin .formRow input:password").focus(function() {
		$(this).addClass("focussed");
	});
	$("#clientLogin .formRow input:password").blur(function() {
		if (!$(this).attr("value")) {
			$(this).css({display:"none"});
			$("#passwordVis").css({display:"block"});
		}
		$(this).removeClass("focussed");
	});
	$("#login-username").focus(function() {
		if ($(this).attr("value") == $labelUser) {
			$(this).attr("value","");
		}
		$(this).addClass("focussed");
	});
	$("#login-username").blur(function() {
		if (!$(this).attr("value")) {
			$(this).attr("value",$labelUser);
		}
		$(this).removeClass("focussed");
	});
	$("#login:not(.error) form").hide();
	$("#login").css({"display":"block"});
$(".auxContent #optSelects div").hide();
	$(".auxContent #optSelects").append('<p><a href="#" id="optSelectsReveal" class="showOpt">More Options&hellip;</a></p>');
	
	$(".auxContent #optSelectsReveal").click(function() {
		if ($(this).attr("class") == "showOpt") {
			$(this).html("Less Options&hellip;");
			$("#optSelects div").slideDown();
			$(this).attr("class", "hideOpt");
		} else {
			$(this).html("More Options&hellip;");
			$("#optSelects div").slideUp();
			$(this).attr("class", "showOpt");
		}
		return false;
	});
});