/* Copyright Bridgeline Software, Inc. An unpublished work created in 2009. All rights reserved. 
This software contains the confidential and trade secret information of Bridgeline Software, Inc. ("Bridgeline").  
Copying, distribution or disclosure without Bridgeline's express written permission is prohibited. */

// Edit Mode Miscellaneous Functions
$(function(){
    if(document.getElementById('jsInclude')){
       $("div.flashContent").addClass('flashEditMode'); 
        // apply padding for a image container in "in the class" template       
        var teachersObjId = $("div.teacheredition").css("top","45px");              
    }
});

// Clear Text Field
function clearTextField(ElemID){
	var tempElem = document.getElementById(ElemID);
	if (tempElem){
		tempElem.value="";
	}
}

function checkSearchField(ElemID){
  var tempElem = document.getElementById(ElemID);
  if(tempElem && tempElem.value==""){
    tempElem.value="Search..."    
    }
}

// Video Player Embedding
$.expr[':'].mov = function(obj) {
    return (obj.href.match(/\.(m4v|mov)$/i));
};

$(document).ready(function() {
    if (typeof (inHome) == "undefined") {
        $('a:mov').addClass('thickbox');
        $('a:mov').each(
                    function(i, val) {
                        //console.log($(this)[0]);
                        try {
                            $(this)[0].href = "/LTRFiles/ModalWindow/videoPlayer.aspx?height=564&width=612&modal=false&movieUrl=" + escape(val);
                        } catch (err) {
                        }
                    }
                );
        tb_init('a.thickbox');
    } else {
        $('a:mov').click(function() {
            var cld = $(this).children();
            if (cld.length > 0 && cld[0].tagName == "IMG") {
                var img = cld[0];
                inHome++
                videoId = "video" + inHome;
                $(this).attr("id", videoId);
                swfobject.embedSWF("/LTRFiles/ModalWindow/smarterville_player-small.swf", videoId, $(cld).width(), $(cld).height(), "9.0.0", "/LTRFiles/ModalWindow/expressInstall.swf", { moviesource: $(this).attr('href'), movieskin: "/LTRFiles/ModalWindow/SkinOverPlaySeekMute.swf" }, null, null);
                // $(this).replaceWith(getVideoPlayerCode($(cld).width(), $(cld).height(), $(this).attr('href')));
            }
            return false;
        }
        );
    }
});

function getVideoPlayerCode(width, height, movieUrl) {
    var source = $("#videoCode").val();
    source = source.replace(/{width}/g, width);
    source = source.replace(/{height}/g, height);
    source = source.replace(/{movieUrl}/g, movieUrl);
    return source;
}

function playGame(swfUrl, width, height, audioUrl, quitUrl, letter, letterCase, gameNumber, letterIndex) {
        swfUrl = swfUrl.replace(/\.swf$/i, '');
        
        width = (width == '') ? 800 : width;
        height = (height == '') ? 600 : height;
        
        AC_FL_RunContent(
				'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0',
				'width', width,
				'height', height,
				'src', swfUrl,
				'quality', 'high',
				'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
				'align', 'middle',
				'play', 'true',
				'loop', 'true',
				'scale', 'showall',
				'wmode', 'window',
				'devicefont', 'false',
				'id', 'LTR_online_all',
				'bgcolor', '#ffffff',
				'name', 'LTR_online_all',
				'menu', 'true',
				'allowFullScreen', 'true',
				'FlashVars', 'audioURL=' + escape(audioUrl) + '&allTextUpperCase=0&callGame=game' + gameNumber + '&showLog=0&quitURL=' + escape(quitUrl) + '&gameLetter=' + letter + '&letterIndex=' + letterIndex + '&gameLetterCase=' + letterCase,
				'allowScriptAccess', 'sameDomain',
				'movie', swfUrl,
				'salign', ''
				); //end AC code

    return false;
}


function playGameK2(swfUrl, width, height, audioUrl, quitUrl, GameID, Grade, Unit, Level, wordListUrl) {
    swfUrl = swfUrl.replace(/\.swf$/i, '');

    width = (width == '') ? 800 : width;
    height = (height == '') ? 600 : height;

    AC_FL_RunContent(
				'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0',
				'width', width,
				'height', height,
				'src', swfUrl,
				'quality', 'high',
				'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
				'align', 'middle',
				'play', 'true',
				'loop', 'true',
				'scale', 'showall',
				'wmode', 'window',
				'devicefont', 'false',
				'id', 'LTR_online_all',
				'bgcolor', '#ffffff',
				'name', 'LTR_online_all',
				'menu', 'true',
				'allowFullScreen', 'true',
				'FlashVars', 'audioURL=' + escape(audioUrl) + '&allTextUpperCase=0&callGame=game' + GameID + '&showLog=0&quitURL=' + escape(quitUrl) + '&grade=' + Grade + '&unit=' + Unit + '&level=' + Level + '&wordlistXMLURL=' + wordListUrl,
				'allowScriptAccess', 'sameDomain',
				'movie', swfUrl,
				'salign', ''
				); //end AC code

    return false;
}
