/********************************
 * 
 * Simple Movie Popup and
 * buttons management JavaScript
 * by Rexirl
 * (yes, that's why the file is
 * named like it is).
 * 
 ********************************/

var SMPBMJ_Blocker = null;
var SMPBMJ_Container = null;
var SMPBMJ_iframe = null;
var SMPBMJ_lgdefault = 1; // make swedish the default language
var SMPBMJ_lg = SMPBMJ_lgdefault;

var SMPBMJ_Movies = new Array(
                              // Invalid language, used for padding
                              Array(),
                              
                              // Swedish
                              Array(Array("http://www.cede-group.se/video/sv/cede_320x180_250kbit_sv.html", 345, 255),
                                    Array("http://www.cede-group.se/video/tunnel/EC240.html", 640, 360),
                                    Array("http://www.cede-group.se/video/ralsmaskin/EW140.html", 640, 360)),
                              
                              // English
                              Array(Array("http://www.cede-group.se/video/en/cede_320x180_250kbit_en.html", 345, 255),
                                    Array("http://www.cede-group.se/video/tunnel/EC240.html", 640, 360),
                                    Array("http://www.cede-group.se/video/ralsmaskin/EW140.html", 640, 360)));

function SMPBMJ_MovieFade(nOpacity, nAddend, nTarget, nDelay, EndCode)
{
	nOpacity += nAddend;
 	if ((nAddend > 0 && nOpacity >= nTarget) || // target has been reached
	    (nAddend < 0 && nOpacity <= nTarget))
	{
		SMPBMJ_Blocker.style.opacity = /*SMPBMJ_Container.style.opacity = */'.' + (nTarget < 10 ? '0' + nTarget : nTarget);
		SMPBMJ_Blocker.style.filter = /*SMPBMJ_Container.style.filter = */'alpha(opacity:' + (nTarget < 10 ? '0' + nTarget : nTarget) + ')';
		if (EndCode)
		{
		    eval(EndCode);
		}
    }
    else // continue the effect
    {
		SMPBMJ_Blocker.style.opacity = /*SMPBMJ_Container.style.opacity = */'.' + (nOpacity < 10 ? '0' + nOpacity : nOpacity);
		SMPBMJ_Blocker.style.filter = /*SMPBMJ_Container.style.filter = */'alpha(opacity:' + (nOpacity < 10 ? '0' + nOpacity : nOpacity) + ')';
		EndCode = (EndCode ? EndCode.replace('\\', '\\\\').replace('\'', '\\\'') : '');
		setTimeout('SMPBMJ_MovieFade(' + nOpacity + ', ' + nAddend + ', ' + nTarget + ', ' + nDelay + ', \'' + EndCode + '\');', nDelay);
	}
}

function SMPBMJ_ViewPopupMovie(nMovie)
{
	SMPBMJ_lg = (lg) ? lg : SMPBMJ_lgdefault;
	
	// If the user is using IE, let them be damned... err, I mean, let's
	// give them a new tab instead of a nice JavaScripted popup.
	if (!window.outerWidth && !window.outerHeight)
	{
		// What do you say about uncommenting the alert below? Ah, sweet dreams...
		//alert("You're using IE! Don't you think you'd do better with a real browser?");
		return true;
	}
	
    var nTotalWidth = (document.body.offsetWidth ? document.body.offsetWidth : window.innerWidth);
    var nTotalHeight = (document.body.offsetHeight ? document.body.offsetHeight : window.innerHeight);

    var body = document.getElementsByTagName("body")[0];

    //var blocker = document.getElementById("SMPBMJ_MovieBlocker");
   var blocker = document.createElement("div");
    blocker.style.position = "absolute";
    blocker.style.left = "0px";
    blocker.style.top = "0px";
    blocker.style.zIndex = 200;
    blocker.style.width = nTotalWidth + "px";
    blocker.style.height = nTotalHeight * 4 + "px";
    blocker.style.backgroundImage = "url('http://www.cede-group.se/km/file/image/addition011009/blocker.png')";
    blocker.onclick = SMPBMJ_ClosePopupMovie;
    //blocker.style.backgroundRepeat = "repeat-all";
    body.appendChild(blocker);

    var container = document.createElement("div");
    container.id = "SMPBMJ_Movie";
     var table = document.createElement("table");
     table.style.width = table.style.minWidth = table.style.maxWidth = SMPBMJ_Movies[SMPBMJ_lg][nMovie][1] + 30 + "px";
	 table.style.height = table.style.minHeight = table.style.maxHeight = SMPBMJ_Movies[SMPBMJ_lg][nMovie][2] + 30 + "px";
	 table.style.overflow = "hidden";
	
     table.setAttribute("cellpadding", "0");
     table.setAttribute("cellspacing", "0");
     table.setAttribute("border", "0");
     
      var tr0 = document.createElement("tr");
       var td00 = document.createElement("td");
       td00.style.fontSize = "5px";
       td00.style.width = td00.style.height = "15px";
       td00.innerHTML = '<img src="http://www.cede-group.se/km/file/image/addition011009/rounded_w2a_topleft.png">';
       tr0.appendChild(td00);
       var td10 = document.createElement("td");
       td10.style.fontSize = "5px";
       td10.style.width = SMPBMJ_Movies[SMPBMJ_lg][nMovie][1] + "px"; td10.style.height = "15px";
       td10.innerHTML = '<img width="' + SMPBMJ_Movies[SMPBMJ_lg][nMovie][1] + 'px" height="15px" src="http://www.cede-group.se/km/file/image/addition011009/rounded_w2a_top.png">';
       tr0.appendChild(td10);
       var td20 = document.createElement("td");
       td20.style.fontSize = "5px";
       td20.style.width = td20.style.height = "15px";
       td20.innerHTML = '<img src="http://www.cede-group.se/km/file/image/addition011009/rounded_w2a_topright.png">';
       tr0.appendChild(td20);
      table.appendChild(tr0);
      var tr1 = document.createElement("tr");
       var td01 = document.createElement("td");
       td01.style.fontSize = "5px";
       td01.style.width = "15px"; td01.style.height = SMPBMJ_Movies[SMPBMJ_lg][nMovie][2] + "px";
       td01.innerHTML = '<img width="15px" height="' + SMPBMJ_Movies[SMPBMJ_lg][nMovie][2] + 'px" src="http://www.cede-group.se/km/file/image/addition011009/rounded_w2a_left.png">';
       tr1.appendChild(td01);
       var td11 = document.createElement("td");
       td11.style.fontSize = "5px";
       td11.style.overflow = "hidden";
       td11.style.width = SMPBMJ_Movies[SMPBMJ_lg][nMovie][1] + "px"; td11.style.height = SMPBMJ_Movies[SMPBMJ_lg][nMovie][2] + "px";
       tr1.appendChild(td11);
       var td21 = document.createElement("td");
       td21.style.fontSize = "5px";
       td21.style.width = "15px"; td21.style.height = SMPBMJ_Movies[SMPBMJ_lg][nMovie][2] + "px";
       td21.innerHTML = '<img width="15px" height="' + SMPBMJ_Movies[SMPBMJ_lg][nMovie][2] + 'px" src="http://www.cede-group.se/km/file/image/addition011009/rounded_w2a_right.png">';
       tr1.appendChild(td21);
      table.appendChild(tr1);
      var tr2 = document.createElement("tr");
       var td02 = document.createElement("td");
       td02.style.fontSize = "5px";
       td02.style.width = td02.style.height = "15px";
       td02.innerHTML = '<img src="http://www.cede-group.se/km/file/image/addition011009/rounded_w2a_bottomleft.png">';
       tr2.appendChild(td02);
       var td12 = document.createElement("td");
       td12.style.fontSize = "5px";
       td12.style.width = SMPBMJ_Movies[SMPBMJ_lg][nMovie][1] + "px"; td12.style.height = "15px";
       td12.innerHTML = '<img width="' + SMPBMJ_Movies[SMPBMJ_lg][nMovie][1] + 'px" height="15px" src="http://www.cede-group.se/km/file/image/addition011009/rounded_w2a_bottom.png">';
       tr2.appendChild(td12);
       var td22 = document.createElement("td");
       td22.style.fontSize = "5px";
       td22.style.width = td22.style.height = "15px";
       td22.innerHTML = '<img src="http://www.cede-group.se/km/file/image/addition011009/rounded_w2a_bottomright.png">';
       tr2.appendChild(td22);
      table.appendChild(tr2);
     container.appendChild(table);
    
    var div = document.createElement("div");
    container.style.margin = "auto";
    container.style.overflow = "hidden";
    container.style.backgroundColor = "transparent";//"#ff0000";
    container.style.zIndex = 301;
    container.style.position = "absolute";
    container.style.left = nTotalWidth / 2.0 - SMPBMJ_Movies[SMPBMJ_lg][nMovie][1] / 2.0 - 15 + "px";
    container.style.top = nTotalHeight / 2.0 - SMPBMJ_Movies[SMPBMJ_lg][nMovie][2] / 2.0 - 15 + "px";
    container.style.width = (SMPBMJ_Movies[SMPBMJ_lg][nMovie][1] + 30) + "px";
    container.style.height = (SMPBMJ_Movies[SMPBMJ_lg][nMovie][2] + 30) + "px";
    td11.appendChild(div);
    
    /*var Closer = document.createElement("div");
    Closer.id = "SMPBMJ_MovieCloser";
    Closer.className = "SMPBMJ_MovieCloser";
    Closer.style.left = nTotalWidth / 2.0 + SMPBMJ_Movies[nMovie][1] / 2.0 - 12 + "px";
    Closer.style.top = nTotalHeight / 2.0 - SMPBMJ_Movies[nMovie][2] / 2.0 - 12 + "px";
    Closer.innerHTML = '<a style="text-decoration: none;" title="Stäng video" href="#" onclick="SMPBMJ_ClosePopupMovie(); return false;">X</a>';
    div.appendChild(Closer);*/

    var iframe = document.createElement("iframe");
    iframe.style.overflow = "hidden";
    iframe.style.background = "transparent";
    iframe.style.width = iframe.style.minWidth = iframe.style.maxWidth = SMPBMJ_Movies[SMPBMJ_lg][nMovie][1] + "px";
    iframe.style.height = iframe.style.minHeight = iframe.style.maxHeight = SMPBMJ_Movies[SMPBMJ_lg][nMovie][2] + "px";
    iframe.style.border = "0px";
    iframe.style.outline = "0px";
    iframe.src = SMPBMJ_Movies[SMPBMJ_lg][nMovie][0];
    div.appendChild(iframe);
    
    //body.appendChild(blocker);
    
    
    SMPBMJ_Blocker = blocker;
    SMPBMJ_Container = container;
    
    blocker.style.opacity = /*container.style.opacity = */'.0';
    blocker.style.filter = /*container.style.filter = */'alpha(opacity=0)';
    blocker.style.display = "";
    SMPBMJ_Blocker.appendChild(SMPBMJ_Container);
    SMPBMJ_MovieFade(0, 5, 60, 10);
    
    return false;
}

function SMPBMJ_ClosePopupMovie()
{
	SMPBMJ_MovieFade(60, -8, 0, 10,
    'if (SMPBMJ_Container && SMPBMJ_Blocker)' +
    '{' + 
    '    SMPBMJ_Container.parentNode.removeChild(SMPBMJ_Container);' +
    '    SMPBMJ_Blocker.style.display = "none";' +
    '}'
    );
}

function Button_MouseOver(Button)
{
	/*var nType = Button.style.backgroundImage.indexOf(".");
	var NewBkg = Button.style.backgroundImage.substr(0, nType) + "_hover" + Button.style.backgroundImage.substr(nType, Button.style.backgroundImage.length);
	Button.style.backgroundImage = NewBkg;*/
	Button.className = Button.className.replace("_normal", "_hover");
	//alert(Button.className);
}
function Button_MouseOut(Button)
{
	/*var nAppend = Button.style.backgroundImage.indexOf("_hover");
	var NewBkg = Button.style.backgroundImage.substr(0, nAppend) + Button.style.backgroundImage.substr(nAppend + "_hover".length);
	Button.style.backgroundImage = NewBkg;*/
	Button.className = Button.className.replace("_hover", "_normal");
}
