/*
 * Common.js
 * This file includes some essential scripts
 */
function fbShare(url) {
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(url),'fbShareWindow','toolbar=0,status=0,width=600,height=480')
}
function twShare(url) {
	window.open('http://twitter.com/home?status='+encodeURIComponent(url),'twShareWindow','toolbar=0,status=0,width=800,height=480')
}
function toHover(imgObj) {
	var origSrc = $(imgObj).attr("src");
	var ext = origSrc.substr(origSrc.length-3,origSrc.length);
	var hoverSrc  = origSrc.substr(0,origSrc.length-4)+"_r."+ext;
	$(imgObj).attr("src",hoverSrc);	
}
function toNormal(imgObj) {
	var hoverSrc = $(imgObj).attr("src");
	var ext = hoverSrc.substr(hoverSrc.length-3,hoverSrc.length);
	var origSrc  = hoverSrc.substr(0,hoverSrc.length-6)+"."+ext;
	$(imgObj).attr("src",origSrc);	
}
$(document).ready(function(){
	/* mouse over */
	$("a.canhover").mouseover(function(){
		toHover($(this).children("img"));
	}).mouseout(function(){
		toNormal($(this).children("img"));
	});
	$("img.canhover").mouseover(function(){
		toHover(this);
	}).mouseout(function(){
		toNormal(this);
	});
	$("#mainNav div[rel!='disabled']").mouseover(function(){
		$(this).addClass("hl");
	}).mouseout(function(){
		if($(this).attr('id')!=$('#mainPrs').attr('id') && $(this).attr('id')!=$('#mainRes').attr('id') && $(this).attr('id')!=$('#mainOrs').attr('id') ){
			$(this).removeClass("hl");
		}
		
	});
	
	var timeout    = 300;
	var closetimer = 0;
	var ddmenuitem = 0;
	var inMenu = false;
	var selectedId = '';
	function jsddm_open(id)
	{  jsddm_canceltimer();
	   jsddm_close(id);
	   ddmenuitem = $('#menu'+id).removeClass("hidden");
	   $('#main'+id).addClass("hl");
	   selectedId=id;
	}
	function jsddm_close(id)
	{ 
		if(ddmenuitem && !inMenu) {
			//alert("I'm :"+id);
			ddmenuitem.addClass("hidden");
			$('#main'+selectedId).removeClass("hl");
			
		} else {
			closetimer = window.setTimeout(jsddm_close, timeout);
		}
	}
	function jsddm_timer()
	{
		closetimer = window.setTimeout(jsddm_close, timeout); 
	}

	function jsddm_canceltimer()
	{
		if(closetimer) {  window.clearTimeout(closetimer);
	      closetimer = null;
	    }
	}
	$(".subNav img").mouseover(function(){
		inMenu = true;
	}).mouseout(function(){
		inMenu = false;
	});
	$('#mainPrs').bind('mouseover', function(){jsddm_open('Prs');});
	$('#mainPrs').bind('mouseout',  function(){jsddm_timer();});
	$('#mainRes').bind('mouseover', function(){jsddm_open('Res');});
	$('#mainRes').bind('mouseout',  function(){jsddm_timer();});
	$('#mainOrs').bind('mouseover', function(){jsddm_open('Ors');});
	$('#mainOrs').bind('mouseout',  function(){jsddm_timer();});
	

	
});
