
//---------------------- Flash loads ----------------------//


// loading music player
var flashvars = {};
var params = {};
params.wmode = "transparent";
var attributes = {};
swfobject.embedSWF(base_url + "assets/front/flash/music/player.swf", "player", "100", "41", "9.0.0", false, flashvars, params, attributes);

//End flash loads

//------------------ Sidebar logo buttons ------------------//

// we have to use jQuery instead of $ because we also use Prototype
jQuery(document).ready(function() {

	//------------------ Initialize ------------------//
	
	// all buttons can be opened at the beginning
	var readyToOpen = true;
	
	// there's no next button to open at the beginning
	var nextToOpen = false;

	// set the .logos span to display: block
	jQuery(".logo").css("dispay","block");
	// set the .logos span to display: none
	jQuery(".logo").hide();
	
	//------------------ Mouse enter ------------------//
	
	jQuery(".links li a").mouseenter(
	  function() {
		  if(!nextToOpen ) {
			  if(!readyToOpen) {
				  nextToOpen = this;
			  } else {
				  openLogo(this);
			  }
		  } else {
			  nextToOpen = this;
			  
		  }
		}
	);
	
	//------------------ Mouse leave ------------------//
	
	jQuery(".links li a").mouseleave(
	
		function() {
			
			if(jQuery(this).hasClass("active")) {
				nextToOpen = false;
				jQuery(this).removeClass("active");
				jQuery(this).children(".logo").slideUp(400, function() {
									readyToOpen = true;
									if(nextToOpen) openLogo(nextToOpen);
								}
							);
			} else {
				nextToOpen = false;
			}
			return false;
		}
	);
	
	//------------------ Open the logo ------------------//
	
	function openLogo(element) {
		if(readyToOpen) {
			readyToOpen = false;
			nextToOpen = false;
			jQuery(element).addClass("active");				
			jQuery(element).children(".logo").slideDown(400);
			return false;
		} 
	}
});

//End sidebar logo buttons


//------------------ Page navigation ------------------//

function getLocation() {
    return window.location.href;
}

function getHref() {
    var url = getLocation();
    var url_elements = url.split('#');
    return url_elements[0];
}


function getHash() {
    var url = getLocation();
    if(url.indexOf('#') > -1) {
        var url_elements = url.split('#');
        return url_elements[url_elements.length-1];
    } else {
        return 'about';
    }
}
window.onload = function() {
	hideALL();
	checkWhetherChanged(0);
	doBlankPopUps();
	/*popup();*/
}

function doBlankPopUps() {
	var links = document.getElementsByClassName('external');
	for (var i = 0; i < links.length; i++) {
		links[i].onclick = function() {
			window.open(this.href, this.firstChild.innerHTML, "");
			return false;
		}
	}
}

/*function popup() {
window.open('popup.html','','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=400,height=300,left=300,top=200');}*/

var timer;

function hideALL() {
	var toHide = document.getElementsByClassName('content_alt');
	if(toHide) {
		for(var i = 0; i < toHide.length; i++) {
			toHide[i].className = 'hide';
		}
	}
	var toDelete = document.getElementsByClassName('to_delete');
	if(toDelete) {
		for(var e = 0; e < toDelete.length; e++) {
			var throwawayNode = toDelete[e].parentNode.removeChild(toDelete[e]);
		}
	}
	
		
}

function checkWhetherChanged(location){
    if(getHash() != location) {
		var hash = getHash();
//		alert(hash);
		var target = document.getElementById(hash + '_cont');
		if(target) {
			var toHide = document.getElementsByClassName('content');
			if(toHide) {
				for(var i = 0; i < toHide.length; i++) {
					toHide[i].className = 'hide';
				}
			}
			target.className = 'content';
		}
    }
	timer = setTimeout("checkWhetherChanged('" + getHash() + "')", 200);
}