function URLEncode(str) {
   var nstr = escape(str);

   nstr = nstr.replace(/\+/g, '%2B');
   nstr = nstr.replace(/\%20/g, '+');

   return nstr;
}
function Set_Cookie( 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() : "" ) +
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

function Get_Cookie( check_name ) {
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false;

	for ( i = 0; i < a_all_cookies.length; i++ ) {
		a_temp_cookie = a_all_cookies[i].split( '=' );
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
		if ( cookie_name == check_name ) {
			b_cookie_found = true;
			if ( a_temp_cookie.length > 1 ) {
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found ) {
		return null;
	}
}



var flashDataSendInt;
var flashData;
var str;
var flashData = "cVolume=="+Get_Cookie("musicVolume")+"||cSongId=="+Get_Cookie("songId")+"||cSongTime=="+Get_Cookie("songTime")+"||cPauseState=="+Get_Cookie("pauseState");

function sendFlashData(){
	str = flashData;
	if(window.musicPlayerFlash) window.musicPlayerFlash.SetVariable("MyVar", str);
	if(document.musicPlayerFlash) document.musicPlayerFlash.SetVariable("MyVar", str);
}
function flashDataReceived(){
	clearInterval(flashDataSendInt);
}
function sendDataToFlash(){
	flashDataSendInt = setInterval("sendFlashData()", 5);
}
function setVolume(wVolume){
	Set_Cookie( "musicVolume", wVolume, 1000, "/");
}
function setSongId(wSongId){
	Set_Cookie( "songId", wSongId, 1000, "/");
}
function setSongTime(wSongTime){
	Set_Cookie( "songTime", wSongTime, 1000, "/");
}
function setPause(wState){
	Set_Cookie( "pauseState", wState, 1000, "/");
}






sfHover = function() {
	$('#sortNav li').hover(
		function(){
			$(this).addClass('sfhover');
		},
		function(){
			$(this).removeClass('sfhover');
		}
	);
}
setupLightBoxLinks = function(){
	$("#contentCol .textItem img, #contentCol .itemContent img")
		.each(function(i){
			imgSrc = $(this).attr("src");
			if (imgSrc.indexOf("_md.jpg") > -1) {
				imgSrc = imgSrc.substring(0, imgSrc.indexOf("_md")) + "_lg.jpg";
			}
			imgCaption = $(this).attr("title");
			$(this).wrap('<a class="imgG" href="'+imgSrc+'" title="'+imgCaption+'"></a>');
		});
	$("#contentCol .imgG").lightBox();
}

$().ready(function(){
	sfHover();
	setupLightBoxLinks();
});






function validateEmail(form_id,email) {
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	var address = document.forms[form_id].elements[email].value;
	if(reg.test(address) == false) {
		return false;
	} else {
		return true;
	}
}



/*
 THIRD FUNCTION
 getPageSize() by quirksmode.com
 
 return Array Return an array with page width, height and window width, height
*/
function ___getPageSize() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
};

/*
 THIRD FUNCTION
 getPageSize() by quirksmode.com
 
 return Array Return an array with page width, height and window width, height
*/
function ___getPageScroll() {
	var xScroll, yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}
	arrayPageScroll = new Array(xScroll,yScroll);
	return arrayPageScroll;
};
