/* tab drop down code */
if (DynAPI) {
initDynAPI()
} else {
	setTimeout('initDynAPI()', 750);
}
//DynAPI.include('dynapi.event.*')
/*
	required javascript libraries for new orc look and feel
*/

function initDynAPI() {
	if (!document.initialized) {
		document.initialized=true;
		DynAPI.setLibraryPath('/jscommon/dynapi2.702/src/lib/'); 
		DynAPI.include('dynapi.api.browser.js');
		DynAPI.include('dynapi.api.dyndocument.js');
		DynAPI.include('dynapi.api.dynlayer.js');
		//if (!(is.platform=='mac' && is.ie) || is.dom) { // stupid mac ie bug
		//DynAPI.include('dynapi.ext.inline2.js')
		//}
	}
}

function finish () {
}

document.initialized=false;
document.lastTab = false;
document.tabsArray = new Array()

function tabOver(obj) {
	if (document.getElementById) {
		var tab = document.getElementById('tab'+obj)
		var ahref = document.getElementById('a_'+obj)
		var dynTab = DynAPI.document.all["tab"+obj]
//alert(DynAPI.document.all)
		if (!dynTab) {
			dynTab = new DynLayer('tab'+obj)
			dynTab.specificCreate();
//			alert(dynTab.getPageX())
			//dynTab.updateValues();
//			DynAPI.document.addChild(dynTab)
//alert(DynAPI.document.addChild)
		}
		if (tab && ahref && dynTab) {
			if (document.lastTab != obj) {
				hidetab(document.lastTab)
				clearTabTimeout(document.lastTab);
			}

			//dynTab.setZIndex(100);
			var x = ahref.offsetLeft - tab.offsetWidth + ahref.offsetWidth;
			x = ahref.offsetLeft
			var y = 27;

			if (x < 5) x = 5;
			dynTab.moveTo(x, y)
			//alert('test')
			tab.style.visibility='visible'
			tabShadow(dynTab)

			
			
		}
		if (document.tabsArray[obj]) clearTabTimeout(obj);
		document.lastTab = obj
	} else {
		return false;
	}
}


function tabOut(obj) {
	document.tabsArray[obj] = setTimeout("hidetab('"+obj+"')", 1000);
}

function tabClick(obj, id) {
	//var dynTab = DynAPI.document.all["tab"+obj]
	if (!document.ORC_store_id) return false;
	
	if (obj == 'watch') {
		return ORC_openPlayer(document.ORC_store_id, id, 'video')
	} else if (obj == 'listen') {
		return ORC_openPlayer(document.ORC_store_id, id, 'audio')
	} else {
	}
	return false;
	//alert('this' + id)
	if (!dynTab) {
		//alert('broken')
	} else {
		return false;
	}
}

function tabLinksOver(obj) {
	clearTabTimeout(obj)
	//alert('tablinksover' + obj)
}
function tabLinksOut(obj) {
	document.tabsArray[obj] = setTimeout("hidetab('"+obj+"')", 500);
	//hidetab(obj)
//	alert('tablinksout' + obj)
}

function clearTabTimeout(obj) {
	if (obj && document.tabsArray[obj]) clearTimeout(document.tabsArray[obj])
}

function hidetab(obj) {
	if (obj && document.getElementById) {
		var tab = document.getElementById('tab'+obj)
		if (tab) {
			tab.style.visibility='hidden';
		}

		var shadow = document.getElementById("tabshadow");
		if (shadow) shadow.style.visibility='hidden'
	} else {
		return false;
	}
}

function tabShadow(tab) {
//return;
if (document.getElementById && DynAPI) {
var shadow2 = document.getElementById('tabshadow');
//alert(shadow2)
	var shadow = new DynLayer("tabshadow")
	//alert(shadow.specificCreate)
	shadow.specificCreate();
	//alert(shadow.css)
	if (shadow.css) {
	//alert('sdfu')
		shadow.css.position="absolute"
	
		shadow.moveTo(tab.getX()+6,tab.getY()+6)
		//alert(tab.getContentWidth())
		
		shadow.setWidth(Math.min(tab.getContentWidth(), 150)-1);
		shadow.setHeight(tab.getContentHeight()-1);
		/*shadow.setBgImage("/images/orc/shadowlight.gif");*/
		shadow2.style.visibility='visible';
		
		//shadow.setVisible(true)

	}
}
}

function showSeries() {
if (document.getElementById) {
	var div = document.getElementById('serieshidelist');
//	alert(div.style.display)
	if (true || div && div.style) {
		div.style.display='block';
	}
	
	div = document.getElementById('serieshidenum');
	if (div && div.style) div.style.display='none';
}
return false;
}




function setupTheme(theme) {
document.themeChosen=theme
window.onload=_themePreview
}

function _themePreview() {
fixThemeLinks()

if (document.getElementById && DynAPI) {
	
	var body = new DynLayer("body");
	body.specificCreate()
	
	var width = body.getContentWidth() - 100;
//	var height = body.getContentHeight() - 150;
	var height = 250;

	var layer = new DynLayer("misc1")
	layer.specificCreate()
	if (!layer.css) {
		layer = new DynLayer("xslmisc1");
		layer.specificCreate()
	}

	if ( body.css && layer.css) {
	var layer2 = document.getElementById(layer.id);
	
	layer.css.position="absolute"
	
	layer.setWidth(width);
	layer.setHeight(height);
	layer.setZIndex(500)
	
	var html = "<div style='background-image:url(/images/orc/shadowlight.gif); position:relative; top:10px; left:10px; '><div style='position:relative; top:-5px; left:-5px; margin-right:10px; margin-bottom:10px; height:150px;background-color:white; border:2px solid #c00; font-family:arial; padding:1em;'>" +
		"<a href=# onclick='return dismissThemePreview()'><img src=/images/orc/icons/close.gif width=10 height=10 border=0 alt='Close' align=right /></a>"+
		"<img src=/images/orc/alert.gif width=56 height=50 alt='!' border=0 align=left />" + 
		"<p style='margin:0;padding:0;margin-left:75'>"+
		"<strong>Theme Preview</strong><br>" + 
		"This is a preview of how this theme will look with your Media Center template.<br><br>" +
		"To apply this theme to your Media Center, you need to <em>select</em> and <em>save</em> this theme. Then click <strong>Update Center</strong> in your Media Center Manager to apply this theme to your Media Center.<br><br>"+
		"</p>"+
		"<a href=# onclick='return dismissThemePreview()' style='text-decoration:none;color:black'><img src=/images/orc/icons/close.gif width=10 height=10 border=0 alt='Close' align=middle /> close this message</a>" +
		"</div></div>"

	if (layer2.innerHTML != null) {
		layer2.innerHTML = html
	} else {
		layer.setHTML(html)
	}
	
	layer.moveTo((body.getContentWidth()-width) / 2,50); //(body.getContentHeight()-height)/2
	document.themeLayer = layer.id
	document.themeTimeout = setTimeout('dismissThemePreview()', 15000);
	
	//alert(((body.getContentWidth()-width) / 2) +","+ ((body.getContentHeight()-height)/2))
	}
}
}

function fixThemeLinks() {
var theme = document.themeChosen
var c = window.document	
if (c.all || c.getElementById) {
	if (c.all)					var links=c.all.tags("A")
	else if (c.getElementById)	var links=c.getElementsByTagName("A")
	var total=links.length
	var str = ""
	for (i=0;i<links.length;i++) {
		if ( (links[i].href.indexOf('javascript') < 0) && (links[i].href.indexOf('#') < 0) ) {
			if (links[i].href.indexOf('?') < 0) { links[i].href += '?' }
			links[i].target = "";
			links[i].href += '&theme='+theme;
		}
	}
}
	
}

			//"javascript:window.top.ccom_admin.mainForm.url.value='"+links[i]+"';window.top.ccom_admin.statusForm.status.value='Loading "+links[i]+"...';window.location='"+links[i]+"';";

function dismissThemePreview() {
	if (document.themeTimeout) clearTimeout(document.themeTimeout)
	
	if (document.themeLayer) {
		var layer = new DynLayer(document.themeLayer);
		layer.specificCreate()
		layer.setVisible(false)
	}
	return false
}

/* menu jump */
function jumpto (obj) {
	var i, value;
	if (obj)
	if (i = obj.selectedIndex)
	if (value = obj.options[i].value) {
		window.location=value;
		return true;
	} else {
		return false;
	}
}

function popWindow(url) {
	var w = window.open(url, 'ccom_popup', 'width=450,height=350,scrollbars');
	if (w) w.focus()
	return false
}

function clickTrack(url) {
	return true;
}

function processOrderForm(obj) {
	var img = new Image()
	img.src = '/images/orc/icons/cart/butn_pleasewait.gif';

	var w = window.open('', 'ccom_order', 'width=400,height=175');
	w.document.write('<html><head>');
	w.document.write('<title>Please wait...</title>')
	w.document.write('<style>')
	w.document.write('body { font-family:arial,verdana; font-size:x-small; } ')
	w.document.write('</style>')
	w.document.write('<script>')
	w.document.write("function closeMe() { setTimeout('window.close()', 1800000); setTimeout('unfocusMe()', 3000)}")
	w.document.write("function unfocusMe() { window.onblur=window.close}")
	w.document.write('window.onload=closeMe')
	w.document.write('</script>')
	w.document.write('</head><body>')

	w.document.write('<h1>Please wait....</h1>')
	w.document.write('<p>Your order is now being processed. This could take a few minutes to finish.</p>')
	w.document.write('<p>Please do not close your browser window before you receive a confirmation Order ID.</p>')

	w.document.write('</body></html>');
	w.document.close();
	w.focus()

	document.processWindow = w
	var f = obj
	if (!f) f = document.mainOrderForm
	if (!f) f = document.forms[0]
	f.onsubmit=stopForm
	if (f.orderBtn) f.orderBtn.src = img.src


	//return false;
	return true;
}
function clearProcessWindowPopUp() {
	if (window) window.focus();
}

function stopForm() {
	if (document.processWindow) document.processWindow.focus()
	return false;
}


/**** Popup Player Code ****/
function ORC_openPlayer(store_id, id, media_type, player, preview) {
if (!media_type) {
	media_type='audio'
}
var url = "/orc/"+store_id+"/player2/"
if (player) {
//	url += "player.php?id="+id+"&media_type="+media_type+"&override_player="+player
	url += "autodetect.php?action=resize&id="+id+"&media_type="+media_type+"&override_player="+player
} else {
	url += "autodetect.php?doresize=1&id="+id+"&media_type="+media_type
}
if (preview) url += "&previewmode=yes"
var w=window.open(url,"CCOM_Player","width=470,height=340,resizable")
if (w) w.focus()
return false;
}

function ORC_openRecommend(store_id, id) {
	var url = "/orc/"+store_id+"/recommend2.php?id="+id
	var w = window.open(url, 'CCOM_Recommend', 'width=470,height=500,resizable');
	if (w) w.focus()
	return false;
}


function showLastYearsLinks(numyears)
{
	var i=0; 
	var d = new Date();
	var year = d.getYear();
	if (year < 1900) year += 1900
	var maxyears = parseInt(numyears)
	for (i=0; i<maxyears; i++) {
		// this block is in here because different browsers treat dates differently... see javascript documentation
		if (year > 1978 && year < 2050) {
			document.write("<li><a href=\"searchItems.jhtml?date=1/1/" + year + "-12/31/" + year + "\">" + year + "</a></li>");
			year--;
		}
	}
	
}
