//Drop Down/ Overlapping Content: http://www.dynamicdrive.com
//Last updated: Dec 19th, 07': Added ability to dynamically populate a Drop Down content using an external file (Ajax feature)

var dropdowncontent={
	disableanchorlink: true, //when user clicks on anchor link, should it be disabled?
	ajaxloadingmsg: "Loading content. Please wait...", //HTML to show while ajax page is being feched
	ajaxbustcache: true, //Bust cache when fetching pages?

	getposOffset:function(what, offsettype){
		return (what.offsetParent)? what[offsettype]+this.getposOffset(what.offsetParent, offsettype) : what[offsettype]
	},


	show:function(anchorobj, subobj, e){
		
		grayOut(true);
		
		var subobjsource=anchorobj.getAttribute("rev")
		if (subobjsource!=null && subobjsource!="")
			this.ajaxconnect(subobjsource, anchorobj.getAttribute("rel"))
			
			
		  var width        = window.innerWidth  ? window.innerWidth  : document.documentElement.clientWidth;
		  var height       = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight;
			subobj.style.left = (document.documentElement.scrollLeft+(width -subobj.clientWidth )/2)+'px';
    	subobj.style.top  = (document.documentElement.scrollTop +(height-subobj.clientHeight)/2)+'px';
			
			
			subobj.style.visibility="visible"
			subobj.startTime=new Date().getTime()
			subobj.contentheight=parseInt(subobj.offsetHeight)
			if (typeof window["hidetimer_"+subobj.id]!="undefined") //clear timer that hides drop down box?
				clearTimeout(window["hidetimer_"+subobj.id])
			//this.slideengine(subobj, (subobj.dropposition[1]=="top")? "up" : "down")
			
	}, 
	
	showyt:function(anchorobj, subobj, e, yturl, w, h){
		
		grayOut(true);
		var ytplayer = subobj.getElementsByTagName("div");
		
		if (!ytplayer[0])
			return;

		//ytplayer[0].innerHTML="<embed src='"+yturl+"' type='application/x-shockwave-flash' wmode='transparent' width='"+w+"' height='"+h+"'></embed></object>";				
		ytplayer[0].innerHTML="<embed src='"+yturl+"' type='application/x-shockwave-flash' wmode='transparent' width='"+w+"' height='"+h+"'></embed>";				

		  var width        = window.innerWidth  ? window.innerWidth  : document.documentElement.clientWidth;
		  var height       = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight;
			subobj.style.left = (document.documentElement.scrollLeft+(width -subobj.clientWidth )/2)+'px';
    	subobj.style.top  = (document.documentElement.scrollTop +(height-subobj.clientHeight)/2)+'px';
			
			
			subobj.style.visibility="visible"
			subobj.startTime=new Date().getTime()
			subobj.contentheight=parseInt(subobj.offsetHeight)
			if (typeof window["hidetimer_"+subobj.id]!="undefined") //clear timer that hides drop down box?
				clearTimeout(window["hidetimer_"+subobj.id])
			this.slideengine(subobj, (subobj.dropposition[1]=="top")? "up" : "down")
		
	
	},
	
	showifrm:function(anchorobj, subobj, e, url, w, h){
		
		grayOut(true);
		var urlSpace = subobj.getElementsByTagName("div");//pokupi sve divove 
		
		//ytplayer[0].innerHTML="<embed src='"+yturl+"' type='application/x-shockwave-flash' wmode='transparent' width='"+w+"' height='"+h+"'></embed>";				
		urlSpace[0].innerHTML="<iframe src='"+url+"' wmode='transparent' width='"+w+"' height='"+h+"' frameBorder='"+0+"'></iframe>";

		  var width        = window.innerWidth  ? window.innerWidth  : document.documentElement.clientWidth;
		  var height       = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight;
			subobj.style.left = (document.documentElement.scrollLeft+(width -subobj.clientWidth )/2)+'px';
    	subobj.style.top  = (document.documentElement.scrollTop +(height-subobj.clientHeight)/2)+'px';
			
			
			subobj.style.visibility="visible"
			subobj.startTime=new Date().getTime()
			subobj.contentheight=parseInt(subobj.offsetHeight)
			if (typeof window["hidetimer_"+subobj.id]!="undefined") //clear timer that hides drop down box?
				clearTimeout(window["hidetimer_"+subobj.id])
			this.slideengine(subobj, (subobj.dropposition[1]=="top")? "up" : "down")
		
	
	},
	
	showss:function(anchorobj, subobj, e, ssurl, w, h){
		
		grayOut(true);
		var ssplayer = subobj.getElementsByTagName("div");
		
		if (!ssplayer[0])
			return;

		//ssplayer[0].innerHTML="<img border='0' src='"+ssurl+"' width='"+w+"' height='"+h+"'/>";
		ssplayer[0].innerHTML="<center><img border='0' src='"+ssurl+"'/></center>";				

		  var width        = window.innerWidth  ? window.innerWidth  : document.documentElement.clientWidth;
		  var height       = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight;
			subobj.style.left = (document.documentElement.scrollLeft+(width -subobj.clientWidth )/2)+'px';
    	subobj.style.top  = (document.documentElement.scrollTop +(height-subobj.clientHeight)/2)+'px';
			
			
			subobj.style.visibility="visible"
			subobj.startTime=new Date().getTime()
			subobj.contentheight=parseInt(subobj.offsetHeight)
			if (typeof window["hidetimer_"+subobj.id]!="undefined") //clear timer that hides drop down box?
				clearTimeout(window["hidetimer_"+subobj.id])
			this.slideengine(subobj, (subobj.dropposition[1]=="top")? "up" : "down")
		
	
	},

	curveincrement:function(percent){
		return (1-Math.cos(percent*Math.PI)) / 2 //return cos curve based value from a percentage input
	},

	slideengine:function(obj, direction){
		var elapsed=new Date().getTime()-obj.startTime //get time animation has run
		if (elapsed<obj.glidetime){ //if time run is less than specified length
			var distancepercent=(direction=="down")? this.curveincrement(elapsed/obj.glidetime) : 1-this.curveincrement(elapsed/obj.glidetime)
			var currentclip=(distancepercent*obj.contentheight)+"px"
			obj.style.clip=(direction=="down")? "rect(0 auto "+currentclip+" 0)" : "rect("+currentclip+" auto auto 0)"
			window["glidetimer_"+obj.id]=setTimeout(function(){dropdowncontent.slideengine(obj, direction)}, 10)
		}
		else{ //if animation finished
			obj.style.clip="rect(0 auto auto 0)";
		}
	},

	hideyt:function(activeobj, subobj, e){
				subobj.style.visibility="hidden"
				subobj.style.left=subobj.style.top=0
				
				grayOut(false);
				var ytplayer = subobj.getElementsByTagName("div");
		
				if (!ytplayer[0])
					return;
		
				ytplayer[0].innerHTML="&nbsp;";				
						
	},
	
	hideifrm:function(activeobj, subobj, e){
				subobj.style.visibility="hidden"
				subobj.style.left=subobj.style.top=0
				
				grayOut(false);
				var urlSpace = subobj.getElementsByTagName("div");
		
				if (!urlSpace[0])
					return;
		
				urlSpace[0].innerHTML="&nbsp;";				
						
	},
	
	hidess:function(activeobj, subobj, e){
				subobj.style.visibility="hidden"
				subobj.style.left=subobj.style.top=0
				
				grayOut(false);
				var ssplayer = subobj.getElementsByTagName("div");
		
				if (!ssplayer[0])
					return;
		
				ssplayer[0].innerHTML="&nbsp;";				
						
	},
	
	hide:function(activeobj, subobj, e){
				subobj.style.visibility="hidden"
				subobj.style.left=subobj.style.top=0
				
				grayOut(false);
	},

	ajaxconnect:function(pageurl, divId){
		var page_request = false
		var bustcacheparameter=""
		if (window.XMLHttpRequest) // if Mozilla, IE7, Safari etc
			page_request = new XMLHttpRequest()
		else if (window.ActiveXObject){ // if IE6 or below
			try {
			page_request = new ActiveXObject("Msxml2.XMLHTTP")
			} 
			catch (e){
				try{
				page_request = new ActiveXObject("Microsoft.XMLHTTP")
				}
				catch (e){}
			}
		}
		else
			return false
		document.getElementById(divId).innerHTML=this.ajaxloadingmsg //Display "fetching page message"
		page_request.onreadystatechange=function(){dropdowncontent.loadpage(page_request, divId)}
		if (this.ajaxbustcache) //if bust caching of external page
			bustcacheparameter=(pageurl.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
		page_request.open('GET', pageurl+bustcacheparameter, true)
		page_request.send(null)
	},

	loadpage:function(page_request, divId){
		if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
			document.getElementById(divId).innerHTML=page_request.responseText
		}
	},

 init:function(anchorid, pos, glidetime){
		var anchorobj=document.getElementById(anchorid)
		var subobj=document.getElementById(anchorobj.getAttribute("rel"))
		//var subobjsource=anchorobj.getAttribute("rev")
		//if (subobjsource!=null && subobjsource!="")
		//	this.ajaxconnect(subobjsource, anchorobj.getAttribute("rel"))
		subobj.dropposition=pos.split("-")
		subobj.glidetime=glidetime || 1000
		subobj.style.left=subobj.style.top=0
		subobj.style.zIndex = 101;
		anchorobj.onclick=function(e){dropdowncontent.show(this, subobj, e); return false;}
		
		// Close link
		var clanchorobj=document.getElementById(anchorid+"_close");
		if (clanchorobj)
			clanchorobj.onclick=function(e){dropdowncontent.hide(subobj, subobj, e); return false;}
	},

 faqInitAndShow:function(subobjid, pos, glidetime){
		var subobj=document.getElementById(subobjid)
		subobj.dropposition=pos.split("-")
		subobj.glidetime=glidetime || 1000
		subobj.style.left=subobj.style.top=0
		subobj.style.zIndex = 101;
		
		// Close link
		var clanchorobj=document.getElementById("faqlink_close");
		if (clanchorobj)
			clanchorobj.onclick=function(e){dropdowncontent.hide(subobj, subobj, e); return false;}
			
		grayOut(true);
		
		  var width        = window.innerWidth  ? window.innerWidth  : document.documentElement.clientWidth;
		  var height       = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight;
			subobj.style.left = (document.documentElement.scrollLeft+(width -subobj.clientWidth )/2)+'px';
    	subobj.style.top  = (document.documentElement.scrollTop +(height-subobj.clientHeight)/2)+'px';
			
			
			subobj.style.visibility="visible"
			subobj.startTime=new Date().getTime()
			subobj.contentheight=parseInt(subobj.offsetHeight)
			if (typeof window["hidetimer_"+subobj.id]!="undefined") //clear timer that hides drop down box?
				clearTimeout(window["hidetimer_"+subobj.id])
			this.slideengine(subobj, (subobj.dropposition[1]=="top")? "up" : "down")
	},

 inityt:function(anchorid, pos, glidetime, yturl, w, h){
		var anchorobj=document.getElementById(anchorid)
		var subobj=document.getElementById(anchorobj.getAttribute("rel"))
		//var subobjsource=anchorobj.getAttribute("rev")
		//if (subobjsource!=null && subobjsource!="")
		//	this.ajaxconnect(subobjsource, anchorobj.getAttribute("rel"))
		subobj.dropposition=pos.split("-")
		subobj.glidetime=glidetime || 1000
		subobj.style.left=subobj.style.top=0
		subobj.style.zIndex = 101; 
		anchorobj.onclick=function(e){dropdowncontent.showyt(this, subobj, e, yturl, w, h); return false;}

		// Close link
		var clanchorobj=document.getElementById(anchorid+"_close");
		if (clanchorobj)
			clanchorobj.onclick=function(e){dropdowncontent.hideyt(subobj, subobj, e); return false;}
	},
	
 initifrm:function(anchorid, pos, glidetime, url, w, h){
		var anchorobj=document.getElementById(anchorid)
		var subobj=document.getElementById(anchorobj.getAttribute("rel"))
		//var subobjsource=anchorobj.getAttribute("rev")
		//if (subobjsource!=null && subobjsource!="")
		//	this.ajaxconnect(subobjsource, anchorobj.getAttribute("rel"))
		subobj.dropposition=pos.split("-")
		subobj.glidetime=glidetime || 1000
		subobj.style.left=subobj.style.top=0
		subobj.style.zIndex = 101; 
		anchorobj.onclick=function(e){dropdowncontent.showifrm(this, subobj, e, url, w, h); return false;}

		// Close link
		var clanchorobj=document.getElementById(anchorid+"_close");
		if (clanchorobj)
			clanchorobj.onclick=function(e){dropdowncontent.hideifrm(subobj, subobj, e); return false;}
	},
	
 initss:function(anchorid, pos, glidetime, ssurl, w, h){
		var anchorobj=document.getElementById(anchorid)
		var subobj=document.getElementById(anchorobj.getAttribute("rel"))
		//var subobjsource=anchorobj.getAttribute("rev")
		//if (subobjsource!=null && subobjsource!="")
		//	this.ajaxconnect(subobjsource, anchorobj.getAttribute("rel"))
		subobj.dropposition=pos.split("-")
		subobj.glidetime=glidetime || 1000
		subobj.style.left=subobj.style.top=0
		subobj.style.zIndex = 101; 
		anchorobj.onclick=function(e){dropdowncontent.showss(this, subobj, e, ssurl, w, h); return false;}

		// Close link
		var clanchorobj=document.getElementById(anchorid+"_close");
		if (clanchorobj)
			clanchorobj.onclick=function(e){dropdowncontent.hideyt(subobj, subobj, e); return false;}
	}
	
 
}

function grayOut(vis, options) {
  // Pass true to gray out screen, false to ungray
  // options are optional.  This is a JSON object with the following (optional) properties
  // opacity:0-100         // Lower number = less grayout higher = more of a blackout 
  // zindex: #             // HTML elements with a higher zindex appear on top of the gray out
  // bgcolor: (#xxxxxx)    // Standard RGB Hex color code
  // grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});
  // Because options is JSON opacity/zindex/bgcolor are all optional and can appear
  // in any order.  Pass only the properties you need to set.
  var options = options || {}; 
  var zindex = options.zindex || 100;
  var opacity = options.opacity || 50;
  var opaque = (opacity / 100);
  var bgcolor = options.bgcolor || '#000000';
  var dark=document.getElementById('darkenScreenObject');
  if (!dark) {
    // The dark layer doesn't exist, it's never been created.  So we'll
    // create it here and apply some basic styles.
    // If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
    var tbody = document.getElementsByTagName("body")[0];
    var tnode = document.createElement('div');           // Create the layer.
        tnode.style.position='absolute';                 // Position absolutely
        tnode.style.top='0px';                           // In the top
        tnode.style.left='0px';                          // Left corner of the page
        tnode.style.overflow='hidden';                   // Try to avoid making scroll bars            
        tnode.style.display='none';                      // Start out Hidden
        tnode.id='darkenScreenObject';                   // Name it so we can find it later
    tbody.appendChild(tnode);                            // Add it to the web page
    dark=document.getElementById('darkenScreenObject');  // Get the object.
  }
  if (vis) {
    // Calculate the page width and height 
    var pageWidth = getScrollWidth() + 'px';
    var pageHeight = getScrollHeight() + 'px';
    $(window).addEvent('resize', function(){resizeDarken()});
     
    //set the shader to cover the entire page and make it visible.
    dark.style.opacity=opaque;                      
    dark.style.MozOpacity=opaque;                   
    dark.style.filter='alpha(opacity='+opacity+')'; 
    dark.style.zIndex=zindex;        
    dark.style.backgroundColor=bgcolor;  
    dark.style.width= pageWidth;
    dark.style.height= pageHeight;
    dark.style.display='block';        
  } else {
     dark.style.display='none';
  }
	if (vis){
		hideCombos();
	} else {
		showCombos();
	}
}

function resizeDarken()
{
  var dark = $('darkenScreenObject');
  if (dark)
  {
	  var pageWidth = getScrollWidth() + 'px';
	  var pageHeight = getScrollHeight() + 'px';
	  
	  dark.style.width= pageWidth;
    dark.style.height= pageHeight;
	}
}

	var combos_to_show;
    function IsIE(){
        return ( navigator.appName=="Microsoft Internet Explorer" );
    }

	function hideCombos(){

        if (!IsIE()){
            return;
        } 

		var c = 0;
		combos_to_show = new Array();
		var combos = document.getElementsByTagName("select");
		if (combos){
	        for (i = 0; i < combos.length; i ++){
	        	if (combos[i].style.display != 'none'){
	        		combos_to_show[c++] = combos[i];
	        		combos[i].style.display = 'none';
	        	}
	        }
        }
	}    
    
    function showCombos(){
        if (!IsIE()) 
        {
            return;

        } 
    
    	if (combos_to_show){
    		for (i = 0; i < combos_to_show.length; i++){
    			combos_to_show[i].style.display='';
    		}
    	}
    	combos_to_show = null;
    }