var hasFlash = false;

function mouseouttest(event){
	var e = event || window.event;
	var ref = document.getElementById('debug_win');

	var tg = (window.event) ? e.srcElement : e.target;
	while (tg.id != 'outcheck' && tg.nodeName != 'BODY') {
		tg = tg.parentNode;
	}
	
	var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
	
	if (!!reltg) {
		while (reltg.id != 'outcheck' && reltg.nodeName != 'BODY') {
			reltg = reltg.parentNode;
		}
		if (reltg.id == 'outcheck')
			return;
	}
	ECC.flashControl.select(0);
}
window.onload =  function fn() {
	if(typeof init == 'function')
		init();
	
	if(typeof refreshCartHTML == 'function')
		refreshCartHTML();
	
	if(typeof setPopups == 'function')
		setPopups();
		
	if(typeof init_other == 'function')
		init_other();
};

function init() {
	var ref_flash = $('flashMovie');
	
	if(ref_flash)
		hasFlash = true;
	
	/*
	 * Add events to menu below the flash slideshow
	 */
	var ref_menu = $('menu2');	
	if(hasFlash && ref_menu){
		var aList = ref_menu.getElementsByTagName('a');
		for(var i=0,l=aList.length;i<l;i++)
		{
			var aTag = aList[i];
			if(aTag.rel.lastIndexOf('push')!= -1){
				var num = aTag.rel.replace("push","");
				aTag.parentNode.onmouseover = new Function("ECC.flashControl.select('"+num+"')");
			}
		}		
	}
	
	/*
	 * Look for a level menu and set it up 
	 */
	var rev_lm = $('levelMenu');
	if(rev_lm){
		var ulList = rev_lm.getElementsByTagName('ul');
		for(var i=0,l=ulList.length;i<l;i++)
		{
			var node = ulList[i].parentNode;

			if ((i+1) == l){
				node.className = 'hvr '+node.className;
			}
			node.onmousedown = new Function("menu_click(this)");
		}
	}
	ECC.flashControl.start(0,false);
	
	ref_flash = null;
	ref_menu = null;
	rev_lm = null;
}
var ECC = {};

ECC.flashControl = {
	
	auto:false,
	
	id:'flashMovie',
	
	altId:'flashMovie2',
	
	currentPage:0,
	
	getEl:function(){
		return $(this.id);
	},
	
	start:function(page,auto){
		if(typeof page != 'undefined')
			this.currentPage = page;
		
		if(typeof auto != 'undefined')
			this.auto = auto;
		
		var ref = this.getEl();
		if(ref){
			var avail = false;
			if(typeof ref.isPageAvaliable != 'undefined'){
				avail = ref.isPageAvaliable(this.currentPage);
			}else{
				var ref2 = $(this.altId);
				if(ref2){
					if(typeof ref2.isPageAvaliable != 'undefined'){
						ref = ref2
						this.id = this.altId;
						avail = ref2.isPageAvaliable(this.currentPage);
					}
				}
			}
			if(avail && typeof ref.playSlideshow != 'undefined'){
				ref.playSlideshow(this.currentPage,this.auto);
			}else{
				setTimeout("ECC.flashControl.start()",100);
			}
		}
		ref = null;
		ref2 = null;
	},
	select:function(num){
		this.currentPage = num;
		var ref = this.getEl();
		if(ref && typeof ref.pushButton != 'undefined'){
			ref.pushButton(num);
		}			
	},
	hide:function(){
		var embedTags = document.getElementsByTagName('embed');

		for(var i=0,l=embedTags.length; i<l; i++){
			embedTags[i].style.visibility = 'hidden';
		}
		
		var objectTags = document.getElementsByTagName('object');

		for(var i=0,l=objectTags.length; i<l; i++){
			objectTags[i].style.visibility = 'hidden';
		}
		
		/*
		var ref = this.getEl();
		if(ref){
			ref.style.visibility = 'hidden';
		}*/		
	},
	show:function(){
		var embedTags = document.getElementsByTagName('embed');

		for(var i=0,l=embedTags.length; i<l; i++){
			embedTags[i].style.visibility = 'visible';
		}
		
		var objectTags = document.getElementsByTagName('object');

		for(var i=0,l=objectTags.length; i<l; i++){
			objectTags[i].style.visibility = 'visible';
		}
		
		
		
		/*
		var ref = this.getEl();
		if(ref){
			ref.style.visibility = 'visible';
		}
		*/
		this.select(this.currentPage);
	}
}

function menu_click(el){
	if(el){
		var topNode = el.parentNode;
	
		if(topNode){
			var ulList = topNode.getElementsByTagName('ul');
			for(var i=0,l=ulList.length;i<l;i++)
			{
				var cn = ulList[i].parentNode.className;
				if(cn.lastIndexOf("hvr") != -1)
					ulList[i].parentNode.className = cn.replace("hvr ","");
			}
		}
		el.className = 'hvr '+el.className;
	}
}

function selectPodcast(id){
	var divs = document.getElementsByTagName('div');
	var ref = document.getElementById('series'+id);
	var ref2 = document.getElementById('podcontrol'+id);
	if(ref && ref2){
		for(var i=0,l=divs.length;i<l;i++){
			if(divs[i].className == 'pod-show'){
				divs[i].className = 'pod-hide';
			}
			if(divs[i].className == 'pod-selected'){
				divs[i].className = 'pod-button';
			}
		}
		ref.className = 'pod-show';
		ref2.className = 'pod-selected';
	}	
}
