/* -- General vars and functions -- */

var requiredMajorVersion = 9;
var requiredMinorVersion = 0;
var requiredRevision = 125;

var userAgent = navigator.userAgent;
var b_name = navigator.appName;
var is_moz = (b_name.indexOf('Microsoft')!=-1);

var kitName = "applewebkit/";
var tempStr = navigator.userAgent.toLowerCase();
var pos = tempStr.indexOf(kitName);
var isAppleWebkit = (pos != -1);

if (is_moz) {
    userAgent = 'ie';
} else if (isAppleWebkit) {
    userAgent = 'safari';
} else if (document.getElementById) {
    userAgent = 'ns';
} else {
    userAgent = 'other';
}

function calc_Window_width() {
    if(document.body.clientWidth) {
        winWidth = document.body.clientWidth;
    } else if(document.getElementsByTagName('body')[0]) {
        winWidth=document.getElementsByTagName('body')[0].clientWidth;
    } else {
        winWidth = window.innerWidth;
    }
    return winWidth;
}

function calc_Window_Height() {
    if(document.body.clientWidth) {
        winHeight = document.body.clientHeight;
    } else if (document.getElementsByTagName('body')[0]) {
        winHeight=document.getElementsByTagName('body')[0].clientHeight;
    } else {
        winHeight = window.innerHeight;
    }
    return winHeight;
}

// Adobe flash version check

var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

function hideAllSelect() {
    if (isIE) {
        var x = document.getElementsByTagName("select");
        for (i = 0; i < x.length; i++) {
            x[i].style.display = "none";
        }
    }
}

function showAllSelect() {
    if (isIE) {
        var x = document.getElementsByTagName("select");
        for (i = 0; i < x.length; i++) {
            x[i].style.display = "";
        }
    }
}

function ControlVersion()
{
	var version;
	var axo;
	var e;

	// NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry

	try {
		// version will be set for 7.X or greater players
		axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		version = axo.GetVariable("$version");
} catch (e) {
}

	if (!version)
{
		try {
			// version will be set for 6.X players only
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
			
			// installed player is some revision of 6.0
			// GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
			// so we have to be careful. 
			
			// default to the first public version
			version = "WIN 6,0,21,0";

			// throws if AllowScripAccess does not exist (introduced in 6.0r47)		
			axo.AllowScriptAccess = "always";

			// safe to call for 6.0r47 or greater
			version = axo.GetVariable("$version");

} catch (e) {
}
}

	if (!version)
{
		try {
			// version will be set for 4.X or 5.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = axo.GetVariable("$version");
} catch (e) {
}
}

	if (!version)
{
		try {
			// version will be set for 3.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = "WIN 3,0,18,0";
} catch (e) {
}
}

	if (!version)
{
		try {
			// version will be set for 2.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			version = "WIN 2,0,0,11";
} catch (e) {
			version = -1;
}
}
	
	return version;
}

// JavaScript helper required to detect Flash Player PlugIn version information
function GetSwfVer(){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	var flashVer = -1;
	
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			var descArray = flashDescription.split(" ");
			var tempArrayMajor = descArray[2].split(".");			
			var versionMajor = tempArrayMajor[0];
			var versionMinor = tempArrayMajor[1];
			var versionRevision = descArray[3];
			if (versionRevision == "") {
				versionRevision = descArray[4];
}
			if (versionRevision[0] == "d") {
				versionRevision = versionRevision.substring(1);
} else if (versionRevision[0] == "r") {
				versionRevision = versionRevision.substring(1);
				if (versionRevision.indexOf("d") > 0) {
					versionRevision = versionRevision.substring(0, versionRevision.indexOf("d"));
}
}
			var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
}
}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	else if ( isIE && isWin && !isOpera ) {
		flashVer = ControlVersion();
}	
	return flashVer;
}



function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
    var str = '';
    if (isIE && isWin && !isOpera)
{
  		str += '<object ';
  		for (var i in objAttrs)
  			str += i + '="' + objAttrs[i] + '" ';
  		str += '>';
  		for (var i in params)
  			str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  		str += '</object>';
} else {
  		str += '<embed ';
  		for (var i in embedAttrs)
  			str += i + '="' + embedAttrs[i] + '" ';
  		str += '> </embed>';
}

    document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
    case "classid":
        break;
    case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
    case "src":
    case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
    case "onafterupdate":
    case "onbeforeupdate":
    case "onblur":
    case "oncellchange":
    case "onclick":
    case "ondblClick":
    case "ondrag":
    case "ondragend":
    case "ondragenter":
    case "ondragleave":
    case "ondragover":
    case "ondrop":
    case "onfinish":
    case "onfocus":
    case "onhelp":
    case "onmousedown":
    case "onmouseup":
    case "onmouseover":
    case "onmousemove":
    case "onmouseout":
    case "onkeypress":
    case "onkeydown":
    case "onkeyup":
    case "onload":
    case "onlosecapture":
    case "onpropertychange":
    case "onreadystatechange":
    case "onrowsdelete":
    case "onrowenter":
    case "onrowexit":
    case "onrowsinserted":
    case "onstart":
    case "onscroll":
    case "onbeforeeditfocus":
    case "onactivate":
    case "onbeforedeactivate":
    case "ondeactivate":
    case "type":
    case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
    case "id":
    case "width":
    case "height":
    case "align":
    case "vspace": 
    case "hspace":
    case "class":
    case "title":
    case "accesskey":
    case "name":
    case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
    default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
}
}
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}

var hasProductInstall = DetectFlashVer(6, 0, 65);
var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);

// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision) {
    versionStr = GetSwfVer();
    if (versionStr == -1 ) {return false;} 
    else if (versionStr != 0) {
        if(isIE && isWin && !isOpera) {
            // Given "WIN 2,0,0,11"
            tempArray = versionStr.split(" "); // ["WIN", "2,0,0,11"]
            tempString = tempArray[1]; // "2,0,0,11"
            versionArray = tempString.split(","); // ['2', '0', '0', '11']
        } else {
            versionArray = versionStr.split(".");
        }

        var versionMajor      = versionArray[0];
        var versionMinor      = versionArray[1];
        var versionRevision   = versionArray[2];

        // is the major.revision >= requested major.revision AND the minor version >= requested minor
        if (versionMajor > parseFloat(reqMajorVer)) {return true;} 
        else if (versionMajor == parseFloat(reqMajorVer)) {
            if (versionMinor > parseFloat(reqMinorVer)) return true;
	   else if (versionMinor == parseFloat(reqMinorVer)) {
                if (versionRevision >= parseFloat(reqRevision)) return true;
            }
        }
        return false;
    }
}

/* -- End of General vars and functions -- */

function playerObj331() {
    this.containerID = 'viewzoom_player_331';
    this.imageContainerID = 'image_331';
    this.containerContents = '';
    this.containerStyle = 'z-index: 1000000;';
    this.container = '';
    this.SWFID = '';
    this.renderType = 'html';
    this.position = 'screen_center';
    this.thumbnail = 'http://data.viewzoom.liveclip.com/thumbnails/4/331.jpg';
    this.position_shift_x = 0;
    this.position_shift_y = 0;
    this.position_abs_x = 0;
    this.position_abs_y = 0;
    this.playerWidth = 530;
    this.playerHeight = 530;
    this.player = 'http://data.viewzoom.liveclip.com/swf/ViewZoomPlayer.swf';
    this.config_url = 'http://data.viewzoom.liveclip.com/4/331/config.xml';
    this.affid = 0;
    this.autoplay_flag = 1;
    this.close_window_flag = 0;
    
    this.generateCode = function() {
        var possible = '1234567890abcdefghijklmnopqrstuvwxyz';
        var length = possible.length;
        var code = '';
        for(i=0;i<10;i++) {code += possible.substr(Math.random(0, length)*30, 1);}
        return code;
    }
    
    this.render = function(type, affid) {
        if ( hasProductInstall && !hasRequestedVersion ) {
            var MMPlayerType = (isIE == true) ? "ActiveX" : "PlugIn";
            var MMredirectURL = window.location;
            document.title = document.title.slice(0, 47) + " - Flash Player Installation";
            var MMdoctitle = document.title;

            AC_FL_RunContent(
                "src", "http://data.viewzoom.liveclip.com/swf/playerProductInstall",
                "FlashVars", "MMredirectURL="+MMredirectURL+'&MMplayerType='+MMPlayerType+'&MMdoctitle='+MMdoctitle+"",
                "width", "214",
                "height", "138",
                "align", "middle",
                "id", "VIAgent",
                "quality", "high",
                "bgcolor", "#00000000",
                "name", "VIAgent",
                "wmode","transparent",
                "allowScriptAccess","sameDomain",
                "type", "application/x-shockwave-flash",
                "pluginspage", "http://www.adobe.com/go/getflashplayer"
            );
        } else if (hasRequestedVersion) {
	   this.renderType = type;
           if (affid) this.affid = affid;
	   this.init();
        } else {
            this.alternateContent = 'Alternate HTML content should be placed here. '
            + 'This content requires the Adobe Flash Player. '
            + '<a href=http://www.adobe.com/go/getflash/>Get Flash</a>';
            document.write(this.alternateContent);
        }
    }

    this.init = function() {
       //this.config_url += this.generateCode();
       document.write('<div id="'+this.containerID+'" style="'+this.containerStyle+'">'+this.containerContents+'</div><div id="image_331"></div>');

       if (userAgent == 'ie' || isIE) this.SWFID = 'obj_viewzoom_player_331';
       else this.SWFID = 'obj_viewzoom_player_331_embed';

       if (!document.getElementById(this.containerID)) {
            this.container = document.createElement("div");
            this.container.id = this.containerID;
            this.container.innerHTML = this.containerContents;
            document.getElementsByTagName('body')[0].appendChild(this.container);
        }

        this.container = document.getElementById(this.containerID);
        if (!this.container) return false;

        switch (this.renderType) {
            case "onclick": {
                this.renderType = 'html';
                if (this.container) {
                    this.container.innerHTML = "<a href=\"#\" onclick=\"Obj331.procced(); return false;\"><img src=\""+this.thumbnail+"\"/></a>";
                }
            } break;
            case "onover": {
                if (this.position == '') this.renderType = 'abs';
                else this.renderType = 'onscreen';

                this.imageContainer = document.getElementById(this.imageContainerID);
                if (this.container && this.imageContainer) {
                    this.imageContainer.innerHTML = "<a href=\"#\" onmouseover=\"Obj331.procced(); return false;\"><img src=\""+this.thumbnail+"\"/></a>";
                }
            } break;
            case "link": {
                if (this.position == '') this.renderType = 'abs';
                else this.renderType = 'onscreen';
            } break;
            case "html": {
                this.renderType = 'html'; 
                this.procced();
            } break;
            case "html_page": {
                this.renderType = 'html'; 
                this.close_window_flag = 1;
                this.procced();
            } break;
            default: {this.autoplay_flag = 0; this.renderType = 'html'; this.procced();} break;
        }
    }

    this.procced = function() {
        this.contparams();
        if (this.container) this.container.style.display = 'block';
        if (this.renderType == 'onscreen') {
            setInterval('Obj331.On_Screen_Handler()', 20);
            this.On_Screen_Handler();
        } else if(this.renderType == 'html') {
            if (this.container) {
                this.container.innerHTML = this.getHtml();
            }
        }
    }

    this.contparams = function() {
        if (typeof(currentPlayer) != 'undefined') currentPlayer.minimizeViewZoom();
        currentPlayer = this;

        SWFID = this.SWFID;

        var container = document.getElementById(this.containerID);
        if (!container) return false;
        if (this.renderType == 'onscreen' || this.renderType == 'abs') {
            hideAllSelect();
            with (container.style){
                height = this.getContainerHeight() + 'px';
                position = this.getContainerPosition();
                width = this.getContainerWidth() + 'px';
                zIndex = this.getContainer_zIndex();
                left = this.getContainer_Style_Left() + 'px';
                top = this.getContainer_Style_Top() + 'px';
            }

            var w = calc_Window_width();
            var h = calc_Window_Height();
            container.innerHTML = this.getHtml();
            if (!document.getElementById(this.containerID+'_background')) {
                bg = document.createElement("div");
                bg.id = this.containerID+'_background';
                document.getElementsByTagName('body')[0].appendChild(bg);
            }
            bg = document.getElementById(this.containerID+'_background');
            bg.innerHTML = '<div id="'+this.containerID+'_background_sub" style="z-index: 999999; position: absolute; width: '+w+'px; height: '+h+'px; top: 0px; left: 0px; background-color: #fff; -moz-opacity: 0; -khtml-opacity: 0; opacity: 0; filter: progid:DXImageTransform.Microsoft.Alpha(opacity=0);"></div>';
        }
        if (this.renderType == 'onscreen') {
            window.onresize = this.On_Screen_Handler;
            window.onscroll = this.On_Screen_Handler;
        }
    }

    this.getHtml = function() {
        var objdef = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="obj_' + this.containerID + '" name="obj_' + this.containerID + '" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0" width="' + this.playerWidth + '" height="' + this.playerHeight + '" align="middle">';

        var params = 'config_url='+this.config_url;

        if (this.autoplay_flag) params += '&autoplay=1';
        if (this.close_window_flag) params += '&close_window_flag=1';
        if (this.renderType!='html' || this.close_window_flag) {
            params += '&showMinimizeButton=1';
        } else params += '&showMinimizeButton=0';
            
        if (this.affid > 0) {
            params += '&affid='+this.affid;
        }

        params += '&self_url='+location.href;
            
        var playdef = '<embed src="'+this.player+'" width="'+this.playerWidth+'" height="'+this.playerHeight+'" loop="false" align="middle" allowScriptAccess="always" wmode="transparent" id="obj_'+this.containerID+'_embed" name="obj_'+this.containerID+'" type="application/x-shockwave-flash" pluginspage="https://www.macromedia.com/go/getflashplayer" FlashVars="'+params+'">';

        var html = objdef;
        html += '<param name="movie" value="'+this.player+'">';
        html += '<param name="wmode" value="transparent">';
        html += '<param name="LOOP" value="false">';
        html += '<param name="allowScriptAccess" value="always">';
        html += '<param name="FlashVars" value="'+params+'">';
        html += playdef;
        html += '</object>';
        return html;
    }

    this.getContainerHeight = function() {
        if (this.renderType == 'onscreen' || this.renderType == 'abs') {v_Height = this.playerHeight;}
        return v_Height;
    }

    this.getContainerPosition = function() {
        if (this.renderType == 'onscreen' || this.renderType == 'abs') {v_Pos = "absolute";}
        return v_Pos;
    }

    this.getContainerWidth = function() {
        if (this.renderType == 'onscreen' || this.renderType == 'abs') {v_Width = this.playerWidth;}
        return v_Width;
    }

    this.getContainer_zIndex = function() {
        if (this.renderType == 'onscreen' || this.renderType == 'abs') {v_zIndex = 1000000;}
        return v_zIndex;
    }

    this.getContainer_Style_Left = function() {
        if (this.renderType == 'onscreen') {v_left = 0;}
        else if (this.renderType == 'abs') {v_left = this.position_abs_x;}
        return v_left;
    }

    this.getContainer_Style_Top = function() {
        if (this.renderType == 'onscreen') {v_top = 0;}
        else if (this.renderType == 'abs') {v_top = this.position_abs_y;}
        return v_top;
    }
    
    this.minimizeViewZoom = function() {
        var el = document.getElementById(this.containerID);
        el.setAttribute('style','');
        el.innerHTML = "";
        document.getElementById(this.containerID+'_background').innerHTML="";
        showAllSelect();
    }
    
    this.closeWindow = function() {
        window.close();
    }

    this.playerSetSize = function(x, y, divid) {
        if(userAgent == 'ns') {
            objVIA = document.getElementById("obj_" + divid + "_embed");
        } else {
            objVIA = document.getElementById("obj_" + divid);
        }

        if (objVIA) {
            objVIA.width = x;
            objVIA.height = y;
        }

        this.playerWidth = x;
        this.playerHeight = y;

        this.container = document.getElementById(divid);

        if (this.container) {
            this.container.style.height = this.playerHeight;
            this.container.style.width = this.playerWidth;
        }

        if (this.renderType == 'onscreen' || this.renderType == 'abs') {
            var shader = document.getElementById(this.containerID+"_background_sub");
            if (shader) {
                shader.style.width = calc_Window_width();
                shader.style.height = calc_Window_Height();
            }
        }
    }
    
    this.hideVIA = function(divid) {
        if(document.getElementById && document.getElementById(divid)) {
            document.getElementById(divid).innerHTML = '';
        }

        if(document.all && document.all[divid]) {
            return document.all[divid].innerHTML = '';
        }
    }
    
    this.On_Screen_Handler = function() {
        var left = 0;
        var top = 0;
        var windowWidth = 0;
        var windowHeight = 0;
        var pageXOffset = 0;
        var pageYOffset = 0;
        
        this.container = document.getElementById(this.containerID);
        if (!this.container) return false;

        windowWidth = calc_Window_width();
        windowHeight = calc_Window_Height();

        pageXOffset = this.calc_Screen_XOffset();
        pageYOffset = this.calc_Screen_yOffset();

        left = this.Left_Position_Selector();
        top = this.Top_Position_Selector();

        left += pageXOffset;
        top += pageYOffset;

        left += this.position_shift_x;
        top += this.position_shift_y;

        this.container.style.left = left + 'px';
        this.container.style.top = top + 'px';
    }

    this.calc_Screen_XOffset = function() {
        var XOffset = 0;
        this.container = document.getElementById(this.containerID);
        if (!this.container) return false;
        if (window.pageXOffset) {XOffset = window.pageXOffset;}
        else if(document.documentElement && document.documentElement.scrollLeft){XOffset = document.documentElement.scrollLeft;} 
        else if(document.getElementsByTagName('body')[0]){XOffset = document.getElementsByTagName('body')[0].scrollLeft;}
        return XOffset;
    }

    this.calc_Screen_yOffset = function() {
        var YOffset = 0;
        this.container = document.getElementById(this.containerID);
        if (!this.container) return false;
        if (window.pageYOffset) {YOffset = window.pageYOffset;}
        else if(document.documentElement && document.documentElement.scrollTop){YOffset = document.documentElement.scrollTop;}
        else if(document.getElementsByTagName('body')[0]){YOffset = document.getElementsByTagName('body')[0].scrollTop;}
        return YOffset;
    }

    this.Left_Position_Selector = function() {
        var lpos = 0;
        this.container = document.getElementById(this.containerID);
        if (!this.container) return false;
        if (self.innerHeight) { // all except Explorer
            winWidth = self.innerWidth;
        } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
            winWidth = document.documentElement.clientWidth;
        } else if (document.body) { // other Explorers
            winWidth = document.body.clientWidth;
        }
        switch (this.position) {
            case 'right_upper': lpos += winWidth - this.playerWidth-50; break;
            case 'left_lower': break;
            case 'left_upper': break;
            case 'right_lower': lpos += winWidth - this.playerWidth; break;
            case 'screen_center': lpos += winWidth/2 - this.playerWidth/2; break;
            case 'left_middle': break;
            case 'right_middle': lpos += winWidth - this.playerWidth; break;
            case 'bottom_middle': lpos += winWidth/2 - this.playerWidth/2; break;
            case 'top_middle': lpos += winWidth/2 - this.playerWidth/2; break;
        }
        return lpos;
    }

    this.Top_Position_Selector = function() {
        var tpos = 0;
        this.container = document.getElementById(this.containerID);
        if (!this.container) return false;
        if (self.innerHeight) { // all except Explorer
            winHeight = self.innerHeight;
        } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
            winHeight = document.documentElement.clientHeight;
        } else if (document.body) { // other Explorers
            winHeight = document.body.clientHeight;
        }
        switch (this.position) {
            case 'right_upper': break;
            case 'left_lower': tpos += winHeight - this.playerHeight; break;
            case 'left_upper': break;
            case 'right_lower': tpos += winHeight - this.playerHeight; break;
            case 'screen_center': tpos += winHeight/2 - this.playerHeight/2; break;
            case 'left_middle': tpos += winHeight/2 - this.playerHeight/2; break;
            case 'right_middle': tpos += winHeight/2 - this.playerHeight/2; break;
            case 'bottom_middle': tpos += winHeight - this.playerHeight; break;
            case 'top_middle': break;
        }
        return tpos;
    }
}

var Obj331 = new playerObj331();
var videoPlayer = Obj331;
