

// Open a works search dialog
worksSearchSubmit = function ( root )
{
	if ( $ ( '#worksSearch' ).val().length > 0 )
	{
		window.open ( root + 'worksearch.axd?q=' + escape ( $ ( '#worksSearch' ).val() ),'workssearch',
			'height=550,width=650,location=0,statusbar=1,menubar=0,resizable=1,scrollbars=1' );
	}
}


// similar to PHP function, removes slashes from strings i.e. I can\'t find a string
function stripslashes(str) {
	str=str.replace(/\\'/g,'\'');
	str=str.replace(/\\"/g,'"');
	str=str.replace(/\\\\/g,'\\');
	str=str.replace(/\\0/g,'\0');
	return str;
}


/* 
DYNAMICALLY CHANGE THE HEIGHT OF THE BACKGROUND FLASH MOVIE
*/


function setBG() {
	$('#flash-bg').height($('#container').height() + 50);
}


/*
	UPDATING FOOTER WIDTH
	*/

function setFooterWidth() {	
	var contentHeight = $('#left-large').height();
	var contentHeight2 = $('#left-large2').height();
	var sideHeight = $('#right-col').height();
	var landingHeight = $('.landing-area').height();
	var homeHeight = $('.home-area').height();

	if((contentHeight + 7) <= sideHeight && contentHeight) {
		$('#footer').addClass('footer-wide');	
	}	
	else if((contentHeight2 + 7) <= sideHeight && contentHeight2) {
		$('#footer').addClass('footer-wide');
	}
	else if(landingHeight > 1 || homeHeight > 1) {
		$('#footer').addClass('footer-wide');
	}
	else {
		$('#footer').addClass('footer-standard');

	}
}


function setup() {

	//setBG();

	setFooterWidth();


	
	/* 
	WATERMARKING TEXT INPUTS IN FOOTER
	*/
	
	$(".login-username").focus(function() {
		if((this).value=="user name") {
			$(this).attr("value","");
		}
	});

	$(".login-username").blur(function() {
		if((this).value=="") {
			$(this).attr("value","user name");
		}
	});


	$(".login-password").focus(function() {
		if((this).value=="password") {
			$(this).attr("value","");
		}	
	});

	$(".login-password").blur(function() {
		if((this).value=="") {
			$(this).attr("value","password");
		}
	});	


	/*
	FAQS ACCORDIAN
	*/

	$('.faqs-expand dt').toggle(function(){		
		$(this)
			.addClass('opened')				
				.next('dd')
					.slideDown(65);
		$("a:first",this).text('close');
	},function(){		
		$(this)
			.removeClass('opened')
				.next('dd')
					.slideUp(65);
		$("a:first",this).text('expand')
	});

}



function isUndefined(v) {
    var undef;
    return v===undef;
}


/* popup window */
function link_popup(src, features) {
    // to be used in an html event handler as in: <a href="..." onclick="link_popup(this,...)" ...
    // pops up a window grabbing the url from the event source's href
    return raw_popup(src.getAttribute('href'), src.getAttribute('target') || '_blank', features);
}

// These defaults should be changed the way it best fits your site
var _POPUP_FEATURES = '';

function raw_popup(url, target, features) {
    // pops up a window containing url optionally named target, optionally having features
    if (isUndefined(features)) features = _POPUP_FEATURES;
    if (isUndefined(target  )) target   = '_blank';
    var theWindow = window.open(url, target, features);
    theWindow.focus();
    return theWindow;
}



/*
 * Popup window script 
 *  
 * Example markup 
 * <a href="mypage.html" onclick="popUpWin(this.href,'console',660,520);return false;" title="Open popup window">Link text</a>
 */

var newWindow = null;
function closeWin(){
	if (newWindow != null){
		if(!newWindow.closed)
			newWindow.close();
	}
}

function popUpWin(url, type, strWidth, strHeight){
	closeWin();
	if (type == "fullScreen"){
		strWidth = screen.availWidth - 10;
		strHeight = screen.availHeight - 160;
	}
	var tools="";
	if (type == "standard" || type == "fullScreen") tools = "resizable,toolbar=yes,location=yes,scrollbars=yes,menubar=yes,width="+strWidth+",height="+strHeight+",top=0,left=0";
	if (type == "console") tools = "resizable,toolbar=no,location=no,scrollbars=yes,width="+strWidth+",height="+strHeight+",left=0,top=0";
	newWindow = window.open(url, 'newWin', tools);
	newWindow.focus();
}
