/* SR c scripts

UPDATES
2005-12-11 by Erik Sandelin
File created. Most scripts copied from www.sr.se/Diverse/script/basic.js

*/


// GENERAL STUFF ///////////////////////////////////////////////////////////////////

// handles body.onload events
function init() {
	
	// window.document.srcmovie.focus();  // this caused strange behaviour in IE
}

// handle window onResize event 	
window.onresize = windowResized;


// FLASH RESIZE ////////////////////////////////////////////////////////////////////

/*
TODO: det verkar inte funka att ladda storlek i IE förrän onLoad... kolla så att flashlagret ritas rätt från början
*/

	
// call flash when browser window is resized
// and pass widht and height info
function windowResized() {
	var sizeObj = getBrowserSize();
	// alert("resize: w=" + sizeObj.width + " h=" + sizeObj.height);
	
	flashProxy.call('onBrowserResize', sizeObj.width, sizeObj.height);	
}

// returns the available width and height of the browser window
function getBrowserSize() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		var scrollBar = 18;	// firefox scrollbar offset
		var yOff = 1;		// otherwise the vertical scrollbar will show in firefox
		myWidth = window.innerWidth - scrollBar;
		myHeight = window.innerHeight - yOff;
	}
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	}
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	//window.alert( 'Width = ' + myWidth );
	var o = new Object();
	o.width = myWidth;
	o.height = myHeight ;
	return o;
}


/* 
Methods for resizing the flash stage at runtime.

setFlashWidth(divid, newW)
divid: id of the div containing the flash movie.
newW: new width for flash movie

setFlashWidth(divid, newH)
divid: id of the div containing the flash movie.
newH: new height for flash movie

setFlashSize(divid, newW, newH)
divid: id of the div containing the flash movie.
newW: new width for flash movie
newH: new height for flash movie

canResizeFlash()
returns true if browser supports resizing flash, false if not. 
*/
function setFlashWidth(divid, newW){
	//alert("set width to:" + newW);
	document.getElementById(divid).style.width = newW+"px";
}
function setFlashHeight(divid, newH){
	document.getElementById(divid).style.height = newH+"px";		
}
function setFlashSize(divid, newW, newH){
	setFlashWidth(divid, newW);
	setFlashHeight(divid, newH);
}
function canResizeFlash(){
	var ua = navigator.userAgent.toLowerCase();
	var opera = ua.indexOf("opera");
	if( document.getElementById ){
		if(opera == -1) return true;
		else if(parseInt(ua.substr(opera+6, 1)) >= 7) return true;
	}
	return false;
}




// Popupfönster /////////////////////////////////////////////////////////////////////
function popWin(whatUrl,bredd,hojd) {
	window.open(whatUrl,'_blank','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,copyhistory=0,width='+bredd+',height='+hojd);
}

// poppa ett fönster med namn
function popNamedWin(whatUrl,name,bredd,hojd) {
	window.open(whatUrl,name,'toolbar=0location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,copyhistory=0,width='+bredd+',height='+hojd);
}

function popWinExt(whatUrl,bredd,hojd,para) {
	window.open(whatUrl,'_blank',para + ',width='+bredd+',height='+hojd);
}

function popPrint(whatUrl,bredd,hojd) {
	window.open(whatUrl,'_blank','toolbar=1,location=0,directories=0,status=0,menubar=1,scrollbars=1,resizable=0,copyhistory=0,width='+bredd+',height='+hojd);
}

function popWinMax(whatUrl) {
	var win = window.open(whatUrl,'_blank','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,copyhistory=0');
	if(screen) {
		win.moveTo(0,0);
		win.resizeTo(screen.availWidth, screen.availHeight);
	}
}

function popPlayer(namn) {
	popNewPlayer(namn) 
}

function chkPlayerWindow(){
	if(webbradioWin==null || webbradioWin.closed){
		alert('Du måste tillåta extrafönster ("pop-up")')
	} else {
	webbradioWin.focus();
	}
}


function popNewPlayer(namn) {
 if (namn != null) {
  	webbradioWin = window.open('http://www.sr.se/webbradio/start.asp?' +namn,'webbradio','width=348,height=485,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,copyhistory=0,resizable=1');
  	chkPlayerWindow();
   }
   else {
	webbradioWin = window.open('http://www.sr.se/webbradio/start.asp','webbradio','width=348,height=485,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,copyhistory=0,resizable=1');
  	chkPlayerWindow();
   } 
}









/*
var layerRef = "document[";
var layerRef2 = "]";
var showRef = "show";
var hideRef = "hide";
if(document.layers) {
	var layerRef = "document["; var layerRef2 = "]"; 
	var showRef = "show"; 
	var hideRef = "hide";
}
else if(document.all) {
	var layerRef = "document.all[";
	var layerRef2 = "].style";
	var showRef = "visible";
	var hideRef = "hidden";
}
else {
	var layerRef = "document.getElementById("; var layerRef2 = ").style";
	var showRef = "visible"; var hideRef = "hidden";
}

function hideLayer(layerName) {
	eval( layerRef + '"' + layerName + '"' + layerRef2 + '.visibility = ' + '"' + hideRef + '"' )
}

function showLayer(layerName) {
	eval( layerRef + '"' + layerName + '"' + layerRef2 + '.visibility = ' + '"' + showRef + '"' )
}

function toggleLayer(whichLayer) {
	if(eval( layerRef + '"' + whichLayer + '"' + layerRef2 + '.visibility == ' + '"' + showRef + '"' )) {	
		hideLayer(whichLayer);
	}
	else {
		showLayer(whichLayer);
	}
}


// RedSheriff standard ID
var rs_id = 0;

// Rollover funktion
function ro(where,which) {
	document.images[where].src = eval(which + ".src");
}

// Byt sida med dropdowner
function ddSwitch(where) {
	if(where.options[where.options.selectedIndex].value != "#") {
		window.location.href=(where.options[where.options.selectedIndex].value);
	}
}
*/
