
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;
jsVersion = 1.1;
function JSGetSwfVer(i){
	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;
			descArray = flashDescription.split(" ");
			tempArrayMajor = descArray[2].split(".");
			versionMajor = tempArrayMajor[0];
			versionMinor = tempArrayMajor[1];
			if ( descArray[3] != "" ) {
				tempArrayMinor = descArray[3].split("r");
			} else {
				tempArrayMinor = descArray[4].split("r");
			}
      		versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
            flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
      	} else {
			flashVer = -1;
		}
	}
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	else {	
		flashVer = -1;
	}
	return flashVer;
} 
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision) 
{
 	reqVer = parseFloat(reqMajorVer + "." + reqRevision);
	for (i=25;i>0;i--) {	
		if (isIE && isWin && !isOpera) {
			versionStr = VBGetSwfVer(i);
		} else {
			versionStr = JSGetSwfVer(i);		
		}
		if (versionStr == -1 ) { 
			return false;
		} else if (versionStr != 0) {
			if(isIE && isWin && !isOpera) {
				tempArray         = versionStr.split(" ");
				tempString        = tempArray[1];
				versionArray      = tempString .split(",");				
			} else {
				versionArray      = versionStr.split(".");
			}
			versionMajor      = versionArray[0];
			versionMinor      = versionArray[1];
			versionRevision   = versionArray[2];
			
			versionString     = versionMajor + "." + versionRevision;   // 7.0r24 == 7.24
			versionNum        = parseFloat(versionString);
        	// is the major.revision >= requested major.revision AND the minor version >= requested minor
			if ( (versionMajor > reqMajorVer) && (versionNum >= reqVer) ) {
				return true;
			} else {
				return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false );	
			}
		}
	}	
	return (reqVer ? false : 0.0);
}
// local
function setGallery(param, dir, altpid, uid){

        //alert ('uid '+uid);
        param = param+''+altpid+''+uid;

        document.writeln('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="770" height="670" id="fgallery" align="middle">');
	document.writeln('<param name="allowScriptAccess" value="sameDomain" />');
	document.writeln('<param name="movie" value="'+dir+'gallery.swf'+param+'" />');
	document.writeln('<param name="quality" value="high" />');
	document.writeln('<param name="name" value="fgallery" />');
	document.writeln('<param name="scale" value="noscale" />');
	document.writeln('<param name="bgcolor" value="#1c1c1e" />');
	document.writeln('<param name="swLiveConnect" value="true" />');
	document.writeln('<embed src="'+dir+'gallery.swf'+param+'" quality="high" scale="noscale" bgcolor="#1c1c1e" width="770" height="670" name="fgallery" id="fgallery-embed" align="middle" swLiveConnect="true" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.writeln('</object>');
}

function size(args) {
  	if(args == "portrait"){
		//tObj.parentNode.style.height = '890px';
		//setSWFDimensions ("fgallery", 770, 880);
		setSWFDimensions ("fgallery", 770, 870);
	} else if(args == "landscape"){
		//tObj.style.height = '670px';
		setSWFDimensions ("fgallery", 770, 670);
	}
}

function initGallery(){
	// TODO
	//alert("command");
}

function setSWFDimensions (objID,width,height) {
	//alert('size: '+objID+' '+width+'x'+height);
		if (objID && width && height) {
			var divObj = document.getElementById("mainFlash");
			var fObj = document.getElementById(objID);
			var fEmb = document.getElementById(objID+'-embed');
			//alert("command:"+objID+" "+fEmb+" "+fObj);
			
			if (divObj != null){
				fObj.style.height = height+'px';
			}
			
			if (fObj && fObj.style) {
				fObj.setAttribute('width',width);
				fObj.setAttribute('height',height);
				fObj.style.width = width+'px';
				fObj.style.height = height+'px';
			}
			
			if (fEmb != null) { 
				fEmb.width = width;
				fEmb.height = height;
				
				if (fEmb.style) { 
					fEmb.style.width = width+'px';
					fEmb.style.height = height+'px';
				}
			}
		}
	}
//



function str2LocationBar(gid){
	var curHref = window.location.href;
	var curHref = window.location.hash;
//	alert('str2LocationBar '+curHref);
	window.location.hash = curHref+'#gid='+gid;
	//window.location.href = curHref+'#gid='+gid;
}
//
var expectedHash = "";
//
function makeHistory(newHash)
{

  //if (newHash != expectedHash) {
   //alert('newHash ' + newHash + ' expectedHash ' + expectedHash);
    window.location.hash = newHash;
    expectedHash = window.location.hash;
  //}
}

//
function teeFlashisAjalugu (args)  {
       //alert("IE NOT: " + args);
       makeHistory('#&pid='+args);
       muudaKommentaariKastiSisu(args);
}
//
function fgallery_DoFSCommand(command, args) {
  if (command == "kuvaAadress") {
    //alert("IE: " + args);
    makeHistory('#&pid='+args);
    muudaKommentaariKastiSisu(args);
  }
  if (command == "size") {
    //alert("IE size: " + args);
    size(args);

  }
}
//
function muudaKommentaariKastiSisu(adre) {
  //alert ('adre='+adre);
   //
  var raamike = document.getElementById("comments");
  //var aadressike = 'index.php?lk_id=20'+adre;
  var aadressike = 'index.php?lk_id=20&pid='+adre;
  //if (raamike) {
    raamike.src = aadressike;
  //}

}

//
function getIdFromQstring ()
{
	//Retrieve Document location and tear off the QueryString values for processing.
	var url = document.location + '';
	q = url.split ('?');
	if (q [1])
	{
		//Get all Name/Value pairs from the QueryString
		var pairs = q [1].split ('&');
		for (i = 0; i < pairs.length; i ++)
		{
			//Get the Name from given Name/Value pair
			var keyval = pairs [i].split ('=');
			if (keyval [0] == 'pid')
			{
				//Get the Value from given Name/Value pair and set to the return ID
				var squareid = keyval [1];
			}
			//
			if (keyval [2] == 'pid')
			{
				//Get the Value from given Name/Value pair and set to the return ID
				var squareid = keyval [3];
			}
		}
	}
	if (squareid)
	{
		return "&amp;pid=" + squareid;
	} else
	{
		return "&amp;ppp=0";
	}
}
//
//
function getPidFromQstring ()
{
	//Retrieve Document location and tear off the QueryString values for processing.
	var url = document.location + '';
	q = url.split ('?');
	if (q [1])
	{
		//Get all Name/Value pairs from the QueryString
		var pairs = q [1].split ('&');
		for (i = 0; i < pairs.length; i ++)
		{
			//Get the Name from given Name/Value pair
			var keyval = pairs [i].split ('=');
			if (keyval [0] == 'pid')
			{
				//Get the Value from given Name/Value pair and set to the return ID
				var squareid = keyval [1];
			}
			//
			if (keyval [2] == 'pid')
			{
				//Get the Value from given Name/Value pair and set to the return ID
				var squareid = keyval [3];
			}
		}
	}
	if (squareid)
	{
		return squareid;
	} else {
    return false;
  }
}
//
function getGidFromQstring ()
{
	//Retrieve Document location and tear off the QueryString values for processing.
	var url = document.location + '';
	q = url.split ('?');
	if (q [1])
	{
		//Get all Name/Value pairs from the QueryString
		var pairs = q [1].split ('&');
		for (i = 0; i < pairs.length; i ++)
		{
			//Get the Name from given Name/Value pair
			var keyval = pairs [i].split ('=');
			if (keyval [0] == 'gid')
			{
				//Get the Value from given Name/Value pair and set to the return ID
				var squareid = keyval [1];
			}
			//
			if (keyval [2] == 'gid')
			{
				//Get the Value from given Name/Value pair and set to the return ID
				var squareid = keyval [3];
			}
		}
	}
	if (squareid)
	{
		return squareid;
	} else
	{
		return false;
	}
}

