/**
 * This script contains embed functions for common plugins. This scripts are complety free to use for any purpose.
 */

function writeFlash(p) {
	writeEmbed(
		'D27CDB6E-AE6D-11cf-96B8-444553540000',
		'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0',
		'application/x-shockwave-flash',
		p
	);
}

function writeShockWave(p) {
	writeEmbed(
	'166B1BCA-3F9C-11CF-8075-444553540000',
	'http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=8,5,1,0',
	'application/x-director',
		p
	);
}

function writeQuickTime(p) {
	writeEmbed(
		'02BF25D5-8C17-4B23-BC80-D3488ABDDC6B',
		'http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0',
		'video/quicktime',
		p
	);
}

function writeRealMedia(p) {
	writeEmbed(
		'CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA',
		'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0',
		'audio/x-pn-realaudio-plugin',
		p
	);
}

function writeWindowsMedia(p) {
	p.url = p.src;
	writeEmbed(
		'6BF52A52-394A-11D3-B153-00C04F79FAA6',
		'http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701',
		'application/x-mplayer2',
		p
	);
}

function writeEmbed(cls, cb, mt, p) {
	var h = '', n;

	h += '<object classid="clsid:' + cls + '" codebase="' + cb + '"';
	h += typeof(p.id) != "undefined" ? 'id="' + p.id + '"' : '';
	h += typeof(p.name) != "undefined" ? 'name="' + p.name + '"' : '';
	h += typeof(p.width) != "undefined" ? 'width="' + p.width + '"' : '';
	h += typeof(p.height) != "undefined" ? 'height="' + p.height + '"' : '';
	h += typeof(p.align) != "undefined" ? 'align="' + p.align + '"' : '';
	h += '>';

	for (n in p)
		h += '<param name="' + n + '" value="' + p[n] + '">';

	h += '<embed type="' + mt + '"';

	for (n in p)
		h += n + '="' + p[n] + '" ';

	h += '></embed></object>';

	document.write(h);
}


// function writeFlash(url,w,h,id,bg,trans) {
// document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="' + w + '" height="' + h + '" id="'+ id + '">\n');
// document.write('<param name="movie" value="' + url + '" />\n');
// document.write('<param name="quality" value="high" />\n');
// document.write('<param name="bgcolor" value="' + bg + '" />\n');
// if (trans == 1) {document.write('<param name="wmode" value="transparent" />\n');}
// document.write('<!--[if !IE]> <-->\n');
// document.write('<object data="' + url + '" width="' + w + '" height="' + h + '" type="application/x-shockwave-flash" name="'+ id + '">\n');
// document.write('<param name="quality" value="high" />\n');
// document.write('<param name="bgcolor" value="' + bg + '" />\n');
// document.write('<param name="pluginurl" value="http://www.macromedia.com/go/getflashplayer" />\n');
// if (trans == 1) {document.write('<param name="wmode" value="transparent" />\n');}
// document.write(' FAIL (the browser should render some flash content, not this).\n');
// document.write(' </object>\n');
// document.write('<!--> <![endif]-->\n');
// document.write('</object>\n');
// }

function returnFlash(url,w,h,id,bg,trans) {
var html = "";
html += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="' + w + '" height="' + h + '" id="'+ id + '">\n';
html += '<param name="movie" value="' + url + '" />\n';
html += '<param name="quality" value="high" />\n';
html += '<param name="allowScriptAccess" value="always" />';
html += '<param name="bgcolor" value="' + bg + '" />\n';
html += '<param name="scale" value="noscale" />\n';
if (trans == 1) {html += '<param name="wmode" value="transparent" />\n';}
html += '<!--[if !IE]> <-->\n';
html += '<object data="' + url + '" width="' + w + '" height="' + h + '" type="application/x-shockwave-flash" swLiveConnect="true" name="'+ id + '">\n';
html += '<param name="allowScriptAccess" value="always" />';
html += '<param name="quality" value="high" />\n';
html += '<param name="scale" value="noscale" />\n';
html += '<param name="bgcolor" value="' + bg + '" />\n';
html += '<param name="pluginurl" value="http://www.macromedia.com/go/getflashplayer" />\n';
if (trans == 1) {html += '<param name="wmode" value="transparent" />\n';}
html += ' FAIL (the browser should render some flash content, not this).\n';
html += ' </object>\n';
html += '<!--> <![endif]-->\n';
html += '</object>\n';
return html;
}

function visit(newURL) {
  var site = window.open(newURL, 'website','scrollbars=1, location=1, menubar=1, status=1, toolbar=1, resizable=1');
  site.window.focus();
}

function popup(newURL, w, h) {
  var popuper = window.open(newURL, 'popup','scrollbars=1, resizeable=1, width=' + w + ', height=' + h);
  popuper.window.focus();
}

mac = navigator.userAgent.indexOf("Mac");
n = navigator.userAgent.indexOf("MSIE");
if( (mac > -1) && (n > -1) ){
	window.location = 'iemac.php'; 
}

function ConfirmAction(msg) {
	var agree=confirm(msg);
	if (agree)
		return true ;
	else
		return false ;
}

function createRequestObject() {
	var ro;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer"){
		ro = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		ro = new XMLHttpRequest();
	}
	return ro;
}

function sndReq(page,target) {
    var http = createRequestObject();
    http.open( 'get', page , true);
    http.onreadystatechange = function(){
         if ( http.readyState == 4 ) {
        var response = http.responseText;
        document.getElementById(target).innerHTML = response;
        http=null;
        }    
    };
    http.send(null);
}

function jumpNav(){
	newPage = document.getElementById('page').selectedIndex;
	destination = document.getElementById('page').options[newPage].value;
	if (destination != 0) location.href = 'index.php?page=' + destination;
}

function playVideo(file){
	document.getElementById('videoPh').style.display = "none";
	document.getElementById('videoPlayer').style.display = "block";
	var url = "/proresources/video_player.swf?toLoad="+file;
	var video = returnFlash(url,456,262,'videop','#cdcdce',1);
	document.getElementById('videoPlayer').innerHTML = video;
}
function emptyVideo(){
	document.getElementById('videoPlayer').style.display = "none";
	document.getElementById('videoPlayer').innerHTML = "";
	document.getElementById('videoPh').style.display = "block";
}

function verticalCenter(target,margin){
	var wH = $(window).height();
	var oH = $(target).height();
	var mH = "-" + Math.floor(oH/2) + "px";
	
	if ( wH <= oH ){
		$(target).css({
			top: margin,
			marginTop: "0px"
		});
	}
	else{
		$(target).css({
			top: "50%",
			marginTop: mH
		});
	}
}
$(document).ready(function(){
	verticalCenter("#innerWrapper","54px");
});
$(window).resize(function(){
	verticalCenter("#innerWrapper","54px");
});
