/* /sites/Clolar/_resources/js/global.js*/ /*
	
	Clolar Global Javascript Functions
	By Christoph Saxe - ISITE Design

*/



// fix a few IE bugs --------------------------------
if(document.all){

	//make sure IE has the abbr and acronym tag
	document.createElement('abbr');
	document.createElement('acronym');

	// prevent ie6 flicker
	try { document.execCommand('BackgroundImageCache', false, true); } catch(e) {}
}

// global variable for text sizing
var sy = {
	textsize	: getCookie("textsize") ? parseInt(getCookie("textsize")) : 76,
	textmin		: 58,
	textdefault : 76,
	textmax		: 112
};


//start the jQuery functions: document.ready ------------------------
$j(document).ready(function() {
		
	$j("a[rel^='prettyPhoto']").prettyPhoto({animationSpeed:'fast',slideshow:10000, social_tools:'', show_title:false, overlay_gallery:false});
	
	var imgCell = $j("#lead .ImageCell");
	if(imgCell){
		imgCell.height($j(imgCell).parent().height());
	}	
		
	// Few setups for IE6
	if(document.all){
		//add class 'over' to drop downs and buttons 
		$j('.nav li, button').hover(
			function() { $j(this).addClass('over'); },
			function() { $j(this).removeClass('over'); }
		);
	}// if document.all

	$j('#site-search input').inputSetter();
	
	$j('#nav li:last').addClass('last');
	
	$j('.glossary_term').tooltip({
		track: false,
		showURL: false,
		showBody:" - ",
		extraClass: "definition",
		top: 20,
		left: -26
	});
	
	// insert print and email actions and run thickbox init		
	if ($j("#share-page a").hasClass("print-page") == false)
	{
	    var mailurl = "/emailpage.aspx?height=535&width=440&url="+window.location;
	    $j("#share-page").html('<a class="email-page" href="'+mailurl+'">'+STRINGS.PAGE_UTILITY_STRINGS.EmailThisPage+'</a><a class="print-page" href="#">'+STRINGS.PAGE_UTILITY_STRINGS.PrintThisPage+'</a>');					
	    $j("#share-page a.print-page").click(function(){ 
		    printCall(); 
		    return false; 
	    });	    
        standard_email_tb_init('#share-page a.email-page');
	}
	
	
	 // reset font size is cookie
    if (getCookie("textsize")) { setTextSize(sy.textsize); }

    // bind text size control
    $j("#large-text").click(function() { changeTextSize("increase"); });
    $j("#regular-text").click(function() { changeTextSize("default"); });
    $j("#small-text").click(function() { changeTextSize("decrease"); });

    // set disable as needed
    if (sy.textsize == sy.textmin) { $j("#small-text").addClass("disabled"); }
    if (sy.textsize == sy.textmax) { $j("#large-text").addClass("disabled"); }


});// document ready / end jquery functions




// Plugins ---------------------------------------------
jQuery.fn.inputSetter = function(lower) {	
	return this.each(function() {
		var $input = $j(this);
		var $label = $j("label[for='"+$input.attr("id")+"']");
		var labeltext = lower && lower==1 ? $label.text().toLowerCase() : $label.text();
		$label.hide();	
		$input.val(labeltext);		
		$input.focus(function() { if (this.value == labeltext) { this.value = ""; }	})
			  .blur(function() { if (!this.value.length) { this.value = labeltext; } });		
	});
};




// non-plugin functions ---------------------------------------------


// based on Maci -- see http://jira.isitedesign.com/browse/MACI-14
function printCall(obj) 
{
    if (typeof(s_gi) == 'function')
    {
        var s=s_gi(s_account);
        if (s && typeof s.tl == 'function')        
            s.tl(obj,"o", STRINGS.PAGE_UTILITY_STRINGS.PrintThisPage);        
    }
    window.print();    
}


// text resizing function -- originally by pdf for Synvisc, modified by xtof for Clolar.
// Relies on ISITE cookie functions.
function changeTextSize(s) {	
	if(s=="increase" && sy.textsize<sy.textmax) {
		sy.textsize+=9;			
		setTextSize(sy.textsize);
	}
	else if(s=="decrease" && sy.textsize>sy.textmin) {	
		sy.textsize-=9;			
		setTextSize(sy.textsize);
	}	
	else if(s=="default" && sy.textsize!=sy.textdefault) {
	    sy.textsize=sy.textdefault;
	    setTextSize(sy.textdefault);
	}
	return false;
}

function setTextSize(v) {
	$j("body").css({ fontSize : sy.textsize+"%" });
	setCookie("textsize", sy.textsize, "", "/");
	
	// set disable as needed
	if(sy.textsize == sy.textmin) { $j("#small-text").addClass("disabled"); }
	if(sy.textsize == sy.textmax) {	$j("#large-text").addClass("disabled"); }
	if(sy.textsize != sy.textmin) {	$j("#small-text").removeClass("disabled");	}
	if(sy.textsize != sy.textmax) {	$j("#large-text").removeClass("disabled");	}	
}


// Cookies get/set/delete
// there is also a jQuery cookie plugin that does more magic but seems to usually be overkill
function getCookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( 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 ) );
}
function setCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) { expires = expires * 1000 * 60 * 60 * 24; }
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+"="+escape( value ) +
		( ( expires ) ? ";expires="+expires_date.toGMTString() : "" ) + //expires.toGMTString()
		( ( path ) ? ";path=" + path : "" ) +
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}
function deleteCookie( name, path, domain ) {
	if ( getCookie( name ) ) document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}
// end cookies


// clean console.log
function cl(logit){ if(window.console&&window.console.firebug) { console.log(logit) } };//cl()
// example: cl("If you use cl() instead of console.log(), it won't break IE when you forget to take it out.");



