// *********************************************
// Function OpenBgImageLookup(script_name)
// *********************************************
function OpenBgImageLookup(script_name)
	{
	// Popup window with links to image library. 
	var popleft=((document.body.clientWidth - 440) / 2)+window.screenLeft; 
	var poptop=(((document.body.clientHeight - 460) / 2))+window.screenTop-40;		
	window.open(script_name,"_blank","resizable=1,scrollbars=yes,width=500,height=450,left="+popleft+",top="+poptop)
	}

// *****************************************************************************************************
// function gotoURL()
// usage: <input type=button value=""Avbryt"" onClick=gotoURL('" & THIS_SCRIPT & "?mode=listSchemas')>
// *****************************************************************************************************
function gotoURL(url)
{
self.location.href = url;
}

// Clear input field on focus
// usage: onFocus="doClear(this)"
// ************************************
 function doClear(theText) {
  //if (theText.value == theText.defaultValue) {
    theText.value = ""
  //}
 refreshImg('imgCaptcha')
 }

// function refreshImg
// ***************************
function refreshImg(valImageId) {
	var objImage = document.images[valImageId];
	if (objImage == undefined) {
		return;
	}
	var now = new Date();
	objImage.src = objImage.src.split('?')[0] + '?x=' + now.toUTCString();
}

// function updateSum - specialare för beställningsformulär
function updateSum() {
document.forms[0].Summa.value = (document.forms[0].Antal_CD_NLP_och_Mental_Träning.value * 198.00) + (document.forms[0].Antal_CD_Omedveten_Närvaro.value * 198.00) + ' SEK, inkl. moms och frakt';
}

// ******************************************************************************************************
// Function that displays wait message when submitting a form
// css-style: .waitMsg {visibility:hidden; color: red; }
// sample code: <span class="waitMsg" ID="id_waitmsg">Loading Data. Please Wait...<br><img id=pbar src="/assets/layout/loading.gif"></span>
// ******************************************************************************************************
function ShowWaitMsg()
{
if(id_waitmsg) id_waitmsg.style.visibility = 'visible';
setTimeout('document.images["pbar"].src = "/assets/layout/loading.gif"', 200);
}

// **********************************
// toggleDiv : Show / Hide functions 
// Used by: listArchive
// **********************************
function toggleElement(id) {
 //var e = document.getElementById(id).style.display = '';
 var e = document.getElementById(id);

 if(e.style.display == 'none')
  e.style.display = '';
 else
  e.style.display = 'none';
 }

// *********************************************************************************************************************
// JW Video Player - Used by editor
// Requires: swfobject.js - 2.2, player.swf
// Editor file: /editor/common/video/video.htm
// Div's required: <div id="videowrapper"><div id=placeholder1></div></div>  <-- must be inserted on the page
// Links, sample: <a href="javascript:initPlayer('/videoplayer/videos/myFlvFile.flv')">Play video 1</a><br>
// **********************************************************************************************************************
function deletePlayer(theWrapper, thePlaceholder, thePlayerId) { 
        swfobject.removeSWF(thePlayerId);
        var tmp=document.getElementById(theWrapper);
        if (tmp) { tmp.innerHTML = "<div id=" + thePlaceholder + "></div>"; }
}

function createPlayer(thePlaceholder, thePlayerId, theFile) {
        var flashvars = {
                file:theFile, 
                autostart:"true",
				stretching:"uniform",
                controlbar:"over",
				backcolor: "2b2c2e",
				frontcolor: "ffffff",
                playlist:"none"
        }
        var params = {
                allowfullscreen:"true", 
                allowscriptaccess:"always"
        }
        var attributes = {
                id:thePlayerId,  
                name:thePlayerId
        }
        swfobject.embedSWF("/editor/common/video/player.swf", thePlaceholder, "100%", "100%", "9.0.115", false, flashvars, params, attributes);
}

function initPlayer(theFile) { 
        deletePlayer('videowrapper', 'placeholder1', 'player1'); 
        createPlayer('placeholder1', 'player1', theFile);
}
// end jw video player

// *********************************************************************************************************************
// TICKERBOX SCRIPT 
// MODIFIED FROM http://www.queness.com/resources/html/slideshow2/index.html //
// CSS - dependencies (add these to the stylesheet)
// ul.tickerbox {list-style:none; width: 220px; height: 150px; overflow:hidden; position:relative; margin:0; padding:0;}	
// ul.tickerbox li {position:absolute; left:0; right:0;}
// ul.tickerbox li.show {z-index:500;}
// *********************************************************************************************************************

$(document).ready(function() {		
	//Execute the tickerbox, (8000 = set 4 seconds for each text, or 2000 x 5 = 10000 - i.e. 5 seconds)
	tickerbox(10000);
});

function tickerbox(speed) {
	//Set the opacity of all list items to 0
	$('ul.tickerbox li').css({opacity: 0.0});
	
	//Get the first text and display it (set it to full opacity)
	$('ul.tickerbox li:first').css({opacity: 1.0});
	
	//Call the tickerfeed function to run the tickerbox	
	var timer = setInterval('tickerfeed()',speed);
	
	//pause the tickerbox on mouse over
	$('ul.tickerbox').hover(
		function () {
			clearInterval(timer);	
		}, 	
		function () {
			timer = setInterval('tickerfeed()',speed);			
		}
	);
	
}

function tickerfeed() {

	//if no list items have the show class, grab the first list item
	var current = ($('ul.tickerbox li.show')?  $('ul.tickerbox li.show') : $('#ul.tickerbox li:first'));

	//Get next list item, if it reached the end of the tickerbox, rotate it back to the first list item
	var next = ((current.next().length) ? ((current.next().attr('id') == 'tickerbox-id')? $('ul.tickerbox li:first') :current.next()) : $('ul.tickerbox li:first'));
		
	//Set the fade in effect for the next list item, show class has higher z-index
	next.css({opacity: 0.0}).addClass('show').animate({opacity: 1.0}, 2000);
	
	//Hide the current list iteme
	current.animate({opacity: 0.0}, 2000).removeClass('show');

}
// END TICKERBOX

// *************************************
// Audio Player - Used by editor
// Requires: swfobject.js - 2.2
// *************************************
     $(document).ready(function() {

        $('a.audio').each(function (i) {
            var audioPlayer = '<object id="audioplayer" name="myaudio" type="application/x-shockwave-flash" data="/Editor/common/audio/player.swf" height="24" width="290">';
			//audioPlayer += '<param name="allowScriptAccess" value="always">;'
            audioPlayer += '<param name="movie" value="/Editor/common/audio/player.swf">';
            audioPlayer += '<param name="FlashVars" value="playerID=' + i + '&soundFile=' + $(this).attr('href') + '&titles=' + $(this).html() + '">';
            audioPlayer += '<param name="quality" value="high">';
            audioPlayer += '<param name="menu" value="false">';
            audioPlayer += '<param name="wmode" value="transparent">';
            audioPlayer += '</object>';
            /*audioPlayer += '<br/><a href=\"' + $(this).attr('href') + '\" target=\"_blank\">download mp3</a>';*/
           $(this).after(audioPlayer).remove();
        });
    });
