
var $j = jQuery.noConflict();

(function($){
$(document).ready(function(){

	$("#menu-main li").removeClass("active");
	$("#menu-main li.frasers").addClass("active");
	
	// Swap Frasers logo on Navigation tab if "active"
	$("#menu-main li.frasers").menuFraserTab();
	$("#menu-main li.home").menuHomeTab();

    // Give nav icon same destination as its link href - hack for IE <= 7
    $("#menu-main li.home img").click(function() {window.location.href = $(this).parent().parent().parent().attr("href");});
    $("#menu-main li.frasers img").click(function() {window.location.href = $(this).parent().parent().parent().attr("href");});
	
	/* Mouseover routine for main navigation */
	$("#menu-main li").hover( function() {	
		$("#menu-main li.active").removeClass("active").addClass("active-disable");
		$(this).addClass("hover");
		$("#menu-main li.frasers").menuFraserTab();
		$("#menu-main li.home").menuHomeTab();
	
	},
		function() {
			$(this).removeClass("hover");
			$("#menu-main li.active-disable").removeClass("active-disable").addClass("active");
			$("#menu-main li.frasers").menuFraserTab();
			$("#menu-main li.home").menuHomeTab();
		}
	
	);
	
	
	/*** CSS image path overrides using cms context root ***/
	/* Main Menu */
	$("#main-body.myCMO #left-nav-container .left-nav-block ul li a").hover(function(){
		$(this).css("background-image","url(" + CMS_CONTEXT_ROOT + "/wp-content/themes/cmo/Images/bullet_arrow-red.gif)");
	},
		function() {
			//$(this).css("background-image","none");
			if ($(this).is("a.active")){
				//do nothing
			} else {
				$(this).css("background-image","none");
			}
		}
	);
	$("#main-body.myCMO #left-nav-container .left-nav-block ul li a.active").css("background-image","url(" + CMS_CONTEXT_ROOT + "/wp-content/themes/cmo/Images/bullet_arrow-red.gif)");
		
	/* Feature Boxes */
	$(".content-home .home-feature-box ul li").css("background-image","url(" + CMS_CONTEXT_ROOT + "/wp-content/themes/cmo/Images/icons_sprite.gif)");
	
	/* PIE - Rounded corners */
	/*$("#main-content-container .button a").css("behavior","url(" + CMS_CONTEXT_ROOT + "/wp-content/themes/cmo/Css/PIE.htc)");	
	$("#container-popup-body form input.btn-login-submit").css("behavior","url(" + CMS_CONTEXT_ROOT + "/wp-content/themes/cmo/Css/PIE.htc)"); 
	$(".login #container-popup-body #left-column .btn-login-register").css("behavior","url(" + CMS_CONTEXT_ROOT + "/wp-content/themes/cmo/Css/PIE.htc)");
	$(".login #container-popup-body #right-column form input.btn-login-submit").css("behavior","url(" + CMS_CONTEXT_ROOT + "/wp-content/themes/cmo/Css/PIE.htc)");
	$("#container-popup-body #full-column form input.btn-login-submit").css("behavior","url(" + CMS_CONTEXT_ROOT + "/wp-content/themes/cmo/Css/PIE.htc)");*/
	
	/*
	$("#main-content-container .button a").css("behavior","url(/css/PIE.htc)");	
	$("#container-popup-body form input.btn-login-submit").css("behavior","url(/css/PIE.htc)"); 
	$(".login #container-popup-body #left-column .btn-login-register").css("behavior","url(/css/PIE.htc)");
	$(".login #container-popup-body #right-column form input.btn-login-submit").css("behavior","url(/css/PIE.htc)");
	$("#container-popup-body #full-column form input.btn-login-submit").css("behavior","url(/css/PIE.htc)");
	*/
	
	
	
	
	/*** Modular popups ***/		
	
	$("#btn-show-login").colorbox({
        width:"695px",
        height:"440px",
        iframe:false,
        opacity:0.5
        
	}); 
	
	/* Login popup for Java */
	if($.browser.msie && jQuery.browser.version < 8){
		$(".modal-password").colorbox();
		$(".modal-login").colorbox({width:"695px", height:"380px", iframe:false, opacity:0.5, inline:true, href:"#login"});  
	} else {
		$(".modal-password").colorbox();
		$(".modal-login").colorbox({width:"695px", height:"345px", iframe:false, opacity:0.5, inline:true, href:"#login"});
	};
	
	/* Login popup for WordPress */	
	/*if($.browser.msie && jQuery.browser.version < 8){
		$("#btn-header-login a").colorbox({
	            width:"695px",
	            height:"480px",
	            iframe:true,
	            opacity:0.5,
	            onClosed:function(){ location.reload(true); }
		});
	} else {
		$("#btn-header-login a").colorbox({
	            width:"695px",
	            height:"480px",
	            iframe:true,
	            opacity:0.5
		});
	};*/
	
	/* Forced resize for Forgot Password modal */
	/*$("#pop-forgot-password").click( function() {
		//alert("resize!");
		if($.browser.msie && jQuery.browser.version < 8){
		
		    parent.jQuery("#colorbox").show().animate({
		    	height:"480px"
		    }, 1800, "easeOutExpo" );
		    parent.jQuery("#cboxWrapper").css("height","480px");
	        parent.jQuery("#cboxContent").css("height","480px");
	        parent.jQuery("#cboxLoadedContent").css("height","480px");
	    } else {
	    	parent.jQuery("#colorbox").show().animate({
		    	height:"455px"
		    }, 1800, "easeOutExpo" );
		    parent.jQuery("#cboxWrapper").css("height","455px");
	        parent.jQuery("#cboxContent").css("height","455px");
	        parent.jQuery("#cboxLoadedContent").css("height","455px");
	    }
    });*/
    
    	
});



/*** Imported from WordPress ***/
/* Swap Frasers logo on main nav tab */
$.fn.menuFraserTab = function() {
	if ($("#menu-main li.frasers").is(".active") || $("#menu-main li.frasers").is(".hover")) {
		$("#menu-main li.frasers img").attr("src",CMS_CONTEXT_ROOT + "/wp-content/themes/cmo/Images/Navigation/tab_frasers-hover.gif");
	} else {
		$("#menu-main li.frasers img").attr("src",CMS_CONTEXT_ROOT + "/wp-content/themes/cmo/Images/Navigation/tab_frasers.gif");
	};	
};

/* Swap Home logo on main nav tab */
$.fn.menuHomeTab = function() {
	if ($("#menu-main li.home").is(".active") || $("#menu-main li.home").is(".hover")) {
		$("#menu-main li.home img").attr("src",CMS_CONTEXT_ROOT + "/wp-content/themes/cmo/Images/Navigation/tab_home-hover.gif");
	} else {
		$("#menu-main li.home img").attr("src",CMS_CONTEXT_ROOT + "/wp-content/themes/cmo/Images/Navigation/tab_home.gif");
	};	
};


})(jQuery)

/*** Incorporated from original Fraser JS files ***/


function showLinkInMsg(_msg) {
    if (_msg != null && _msg.indexOf('&lt;') != -1) {
    	_msg = _msg.replace(/&lt;/g,'<').replace(/&gt;/g,'>');
    }
    return _msg;
}



function showHide(shID) {
    if (document.getElementById(shID)) {

        if (document.getElementById(shID+'-show').style.display != 'none') {

            document.getElementById(shID+'-show').style.display = 'none';
            document.getElementById(shID+'-hide').style.display = 'inline';
            document.getElementById(shID).style.display = 'block';
        }
        else if (document.getElementById(shID+'-show').style.display != 'inline') {

            document.getElementById(shID+'-show').style.display = 'inline';
            document.getElementById(shID+'-hide').style.display = 'none';
            document.getElementById(shID).style.display = 'none';
        }
        else {
            document.getElementById(shID+'-show').style.display = 'inline';
            document.getElementById(shID+'-hide').style.display = 'none';
            document.getElementById(shID).style.display = 'none';
        }
    }
}


/** Checks or unchecks all checkboxes passed by name. */
function toggleCheckboxes(checkItFldObj, form) {
	if (checkItFldObj.checked) {
		checkAll(form);
    } else {
        uncheckAll(form);
    }
}

/** Checks to see if at least on checkbox is checked. */
function someChecked(form) {

		list = form.elements;
        for (i = 0; i < list.length; i++) {
            if (list[i].checked == true ) {
              return true;
           	}
        }
        alert('No check-boxes have been checked.');
        return false;

}

/** Checks all checkboxes. */
function checkAll(form) {
		list = form.elements;
        for (i = 0; i < list.length; i++) {
            list[i].checked = true ;
        }

}

/** Unchecks all fields. */
function uncheckAll(field) {
    if (!field.length) {
        field.checked = false;
    } else {
        for (i = 0; i < field.length; i++) {
            field[i].checked = false ;
        }
    }
}





/* Unchecks the 'Select All' checkbox if an item is unchecked and to check to Select All if all elements are checked. */
function toggleSelectAllBox(checkItFldObj,fldObj) {

	if ((fldObj.checked == false) && (checkItFldObj.checked == true)) {
		checkItFldObj.checked = false;
	}

    if ((fldObj.checked == true) && (checkItFldObj.checked == false)) {
		//list = document.getElementsByName("chkbxFldName");
		list = document.forms['searchResults'].elements;

    	count = 0;
    	for (i = 0; i < list.length; i++) {
			if(list[i].checked) {
	    		count = count + 1;
			}
    	}

    	if(count == list.length) {
    	alert(count);alert(list.length);
        	checkItFldObj.checked = true;
    	}
	}
}


function get_Cookie(name) {
    var start = document.cookie.indexOf(name+"=");
    var len = start+name.length+1;
    if (!start)
      if (name != document.cookie.substring(0,name.length)) return null;
    if (start == -1)
        return null;
    var end = document.cookie.indexOf(";",len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len,end));
}



/* Problems exist when a conversation is terminated and user hits
 BACK button and navigates to a page that requires a conversation
*/
function checkConversationCookie()
{
 	var cookie = get_Cookie("conversation");
	if (cookie == null) {
	  window.location.replace("/public/home.jsf");
	}
}
