imload= new Image(68,68);
imload.src = "/images/loader2.gif";

im3load= new Image();
im3load.src = "/images/onepxtransp.gif";
im4load= new Image();
im4load.src = "/images/edititem.gif";
im5load= new Image();
im5load.src = "/images/xsymbred.gif"
im6load= new Image();
im6load.src = "/images/xsymb.gif"
var popupdiv = 'effectdiv';
var popupdivIE = 'effectdivie';
var popupdiv2 = 'thirdeffectdiv';
var popupdivIE2 = 'thirdeffectdivie';
var popupdivIm = 'effectdivim';
var popupdivImIE = 'effectdivimie';
var flvplayer= '/usermedia/videoartsteps.swf';
var flashskin= '/usermedia/SkinUnderAllNoFullNoCaption.swf';
var popfooter = ''; //<p class="simplest_sml">&copy; Dataverse Ltd 2009</p>';
var MAXWIDTH = 1040;
var OPACITY = 76;
var SELECTEDITEMOPACITY = 100;


var secondlayer=false;

function lockLayer(){
	if(secondlayer){  return false; }
	secondlayer=true;
	return true;
}

function unlockLayer(){
	if(secondlayer){ secondlayer=false; return true; }
	return false;
}

// Netscape
if (document.layers) 
{ 
    document.captureEvents(Event.MOUSEMOVE);
    document.onmousemove = captureMousePosition;
} else if (document.all) { // Internet Explorer
    document.onmousemove = captureMousePosition;
} else if (document.getElementById) { // Netcsape 6
    document.onmousemove = captureMousePosition;
}

var moveit=false;
//var moveit=true;
var xMousePosition = 0;
var yMousePosition = 0;

function captureMousePosition(e) 
{
	xMousePos = 0;
	yMousePos = 0;

    if (document.all) {
        xMousePos = window.event.clientX+document.body.scrollLeft;
        yMousePos = window.event.clientY+document.body.scrollTop;
        //xMousePos = window.event.clientX+document.documentElement.scrollLeft;
        //yMousePos = window.event.clientY+document.documentElement.scrollTop;
    } else {
    	xMousePos = e.clientX+document.body.scrollLeft;
        yMousePos = e.clientY+document.body.scrollTop;
        //xMousePos = e.clientX+document.documentElement.scrollLeft;
        //yMousePos = e.clientY+document.documentElement.scrollTop;
    }
    xMousePosition = xMousePos;
    yMousePosition = yMousePos;
    
  	if(moveit){
        hp = document.getElementById('hoverpopup');
        hp.style.top = yMousePos-10-hp.offsetHeight + 'px';
        if (xMousePos+10+hp.offsetWidth-document.body.scrollLeft<document.body.offsetWidth){
            hp.style.left = xMousePos+10 + 'px';
        }else { hp.style.left = document.body.offsetWidth + document.body.scrollLeft - hp.offsetWidth + 'px'; }
    }
}


function ShowPopup(hoveritem,titletext)
{
	moveit=true;
    pop = document.getElementById('hoverpopup');
    pop.innerHTML=titletext;
    pop.style.visibility = 'Visible';
   	if(document.all){
   		hoveritem.style.filter = 'alpha(opacity='+SELECTEDITEMOPACITY+')';
    }else{
    	hoveritem.style.setProperty("-moz-opacity","0."+SELECTEDITEMOPACITY+"","");
    }
}

function HidePopup(hoveritem)
{
	moveit=false;
    hp = document.getElementById('hoverpopup');
    hp.style.visibility = 'Hidden';
    hp.innerHTML='';
   	if(document.all){
   		hoveritem.style.filter = 'alpha(opacity=100)';
    }else{
    	hoveritem.style.setProperty("-moz-opacity","1","");
    }
}

function inverseHoverOut(hoveritem)
{
   	if(document.all){
   		hoveritem.style.filter = 'alpha(opacity=75)';
    }else{
    	hoveritem.style.setProperty("-moz-opacity","0.75","");
    }
}


function inverseHover(hoveritem)
{
    if(document.all){
   		hoveritem.style.filter = 'alpha(opacity=100)';
    }else{
    	hoveritem.style.setProperty("-moz-opacity","1","");
    }
}


function moveTheDiv()
{
	eff = document.getElementById(popupdivIE);
    eff.style.top = document.body.scrollTop + 'px';
    eff.style.left = document.body.scrollLeft + 'px';
    effim = document.getElementById(popupdivImIE);
    effim.style.top = document.body.scrollTop + 'px';
    effim.style.left = document.body.scrollLeft + 'px';
    //effim = document.getElementById(popupdivImIE2);
    //effim.style.top = document.body.scrollTop + 'px';
    //effim.style.left = document.body.scrollLeft + 'px';

}

function LightIt(hoveritem)
{
   	if(document.all)
   	{
   		hoveritem.style.filter = 'alpha(opacity='+OPACITY+')';
    }
    else
    {
    	hoveritem.style.setProperty("-moz-opacity","0."+OPACITY+"","");
    }
}

function ShadowIt(hoveritem)
{
    hp = document.getElementById('hoverpopup');
    hp.style.visibility = 'Hidden';
    if(document.all)
    {
   		hoveritem.style.filter = 'alpha(opacity=100)';
    }
    else
    {
    	hoveritem.style.setProperty("-moz-opacity","1","");
    }
}


function maxDimensions()
{
	var wheight = document.body.clientHeight - 100;
	var style = "max-height:"+wheight+"px; " +
				"max-width:"+MAXWIDTH+"px; " +
				"height: expression(this.height >= this.width + "+(MAXWIDTH-wheight)+" && this.height > "+wheight+" ? '"+wheight+"px' : true); "+
				"width: expression(this.height < this.width + "+(MAXWIDTH-wheight)+" && this.width > "+MAXWIDTH+" ? '"+MAXWIDTH+"px' : true);";
	return style;
}


function showQTVideo(im,title)
{
	showPop('<table cellspacing=0 cellpadding=0><tr><td style=\"border:1px black solid;\">' +
		'<OBJECT HEIGHT="450" WIDTH="600" CLASSID="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" CODEBASE="http://www.apple.com/qtactivex/qtplugin.cab">' +
		'<PARAM NAME="src" VALUE="'+im+'" >' +
		'<EMBED SRC="'+im+'" bgcolor="#999999" HEIGHT="450" WIDTH="600" TYPE="video/quicktime" PLUGINSPAGE="http://www.apple.com/quicktime/download/"/>'+
		'</OBJECT></td></tr></table>',false,title);
}


function showFlashVideo(im,title)
{
	showPop('<script type="text/javascript">' +
			'function getsource(){ '+
				'return "'+im+'"; '+
			'}' +
			'function getskin(){'+ 
				'return "' + flashskin + '"; '+
			'}' +
			//'var getskin=getskin(); var getsource=getsource();'+
		'</script>' +
		'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="640" height="518" id="viedoemst" align="middle">' +
		'<param name="allowScriptAccess" value="sameDomain" />' +
		'<param name="allowFullScreen" value="false" />'+
		'<param name="movie" value="'+flvplayer+'" />' +
		'<param name="quality" value="high" />' +
		'<param name="bgcolor" value="#999999" />' +	
		'<embed src="'+flvplayer+'" quality="high" bgcolor="#999999" width="640" height="518" name="videoemst" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />' +
		'</object>',false,title);
}


function showVimeoVideo(key,title)
{
	showPop
	(
	 '<embed height="360" width="640" flashvars="clip_id='+key+'&amp;server=vimeo.com&amp;autoplay=0&amp;fullscreen=1&amp;md5=0&amp;show_portrait=0&amp;show_title=0&amp;show_byline=0&amp;context=user:450090&amp;context_id=&amp;force_embed=0&amp;multimoog=&amp;color=00ADEF&amp;force_info=undefined" wmode="transparent" scalemode="showAll" allowfullscreen="true" allowscriptaccess="always" quality="high" bgcolor="#ffffff" name="vimeo_clip_'+key+'" id="vimeo_clip_'+key+'" style="" src="http://www.vimeo.com/moogaloop_local.swf?ver=29263" type="application/x-shockwave-flash"/>'
		,false,title
	);
}


function showYoutubeVideo(key,title)
{
	showPop
	(
		'<object width="560" height="340">' +
			'<param name="movie" value="http://www.youtube.com/v/' + key +'&hl=en&fs=1&"></param>' +
			'<param name="allowFullScreen" value="true"></param>' +
			'<param name="allowscriptaccess" value="always"></param>' + 
			'<embed src="http://www.youtube.com/v/'+key+'&hl=en&fs=1&" '+
				'type="application/x-shockwave-flash" '+
				'allowscriptaccess="always" '+
				'allowfullscreen="true" '+
				'width="560" '+
				'height="340">'+
			'</embed>'+
		'</object>'
		,false,title
	);
}


function smartPopUp(item,title)
{
	if(item.match(new RegExp('^.*\.[fF][lL][vV]$')))
	{
		showFlashVideo(item,title);
	}
	else if(item.match(new RegExp('^.*\.([jJ][pP][gG]|[pP][nN][gG]|[gG][iI][fF])$')))
	{
		showTheImage(item,title);
	}
	else if(item.match(new RegExp('^.*\.[qQ][tT][vV]$')))
	{
		showQTVideo(item,title);
	}
}


function getYoutubeKey(url)
{
	if(new RegExp("^[0-9A-z_]+$").test(url)){ return url; }

	var q = url.split('?');
	var pairs = q[q.length-1].split('&');
	var key = "";
	for(var i in pairs)
	{
		if(pairs[i].length>2 && pairs[i][0] == 'v') 
		{ key = pairs[i].substring(2,pairs[i].length); }
	}
	return key;
}


function getVimeoKey(url)
{
	if(new RegExp("^[0-9A-z_]+$").test(url)){ return url; }

	var surl = url.split('/');
	var q = surl[surl.length-1].split('?');
	return q[0];
}


function showTheImage(im,title)
{
	showTheImageWithoutX('/images/loader2.gif'); 
	var img = new Image();
	img.onload=function(){ _showTheImage(im,title); }
	img.src=im;
}


function _showTheImage(im,title)
{
	showPopIm('<img style="border:0px white solid;'+maxDimensions()+'" class="largeimage" src="'+im+'">',false,title);
}

function showTheImageWithoutX(im)
{
	showPopIm('<img style="border:0px white solid;'+maxDimensions()+'" class="largeimage" src="'+im+'">',true); 
}


function showThePopWithoutX(im)
{
	showPop('<img style="border:0px white solid;'+maxDimensions()+'" class="largeimage" src="'+im+'">',true,''); 
}


function showTheIm(im)
{
	showTheImage(im);
}


function hideTheImage()
{ 
	document.getElementById(popupdivImIE).style.visibility='Hidden'; 
	document.getElementById(popupdivIm).style.visibility='Hidden'; 
	document.getElementById(popupdivImIE).innerHTML='';
	document.getElementById(popupdivIm).innerHTML='';
	//_hideFrame();
	enablescroll();
}


function hideThePop()
{ 
	document.getElementById(popupdivIE).style.visibility='Hidden'; 
	document.getElementById(popupdiv).style.visibility='Hidden'; 
	//document.getElementById(popupdivIE).innerHTML='';
	//document.getElementById(popupdiv).innerHTML='';
	//_hideFrame();
	enablescroll();
}


function hideThePop2()
{ 
	document.getElementById(popupdivIE2).style.visibility='Hidden'; 
	document.getElementById(popupdiv2).style.visibility='Hidden'; 
	//document.getElementById(popupdivIE).innerHTML='';
	//document.getElementById(popupdiv).innerHTML='';
	//_hideFrame();
	unlockLayer();
}


function disablescroll()
{
	if(document.all)
	{
		document.getElementsByTagName("body")[0].style.overflow= "hidden";
	}
	else
	{
		document.getElementsByTagName("body")[0].style.setProperty("overflow","hidden","");
	}
}


function enablescroll()
{
	if(document.all)
	{
		document.getElementsByTagName("body")[0].style.overflow="auto";
	}
	else
	{
		document.getElementsByTagName("body")[0].style.setProperty("overflow","auto","");
	}
}


function hideTheIm()
{
	hideTheImage();
}


var ascript=new Array();
function removeScripts()
{
	if(ascript){ 
		for(var i=0; i<ascript.length; i++){
			document.getElementsByTagName("head")[0].removeChild(ascript[i]);
		}
	}
	ascript.length=0;
}


function _showPop(text,noX,img,func,title)
{
	__showPop(text,noX,img,func,'popupwindowtable','popupwindowinnertable',title);
}

function __showPop(text,noX,img,func,class1,class2,title)
{
	if(!title){ title=' '; }
	disablescroll();
	//insertJscript(text);
	var thediv='<div style="background:black; filter:alpha(opacity='+OPACITY+'); -moz-opacity:0.'+OPACITY+'; opacity:0.'+OPACITY+'; width:100%; height:100%;"></div>';
    var style='style="background:black; opacity:0.'+OPACITY+'; filter:alpha(opacity='+OPACITY+'); -moz-opacity:0.'+OPACITY+';"';
    var pos;
    if (document.all){ pos = 'absolute'; }
  	else { pos = 'fixed'; }
	var htm = '';
	//htm+='<div id="popupsupercontainer" style="width:0px; overflow:hidden;">';
    htm+='<div style="text-align:center; vertical-align:middle; height:100%; overflow:auto; width:100%; position:'+pos+'; top:0px; z-index:5; background:black; filter:alpha(opacity='+OPACITY+'); opacity:0.'+OPACITY+'; -moz-opacity:0.'+OPACITY+';"></div>' +
    	'<div style="margin:auto; height:100%; width:100%; overflow:hidden; position:'+pos+'; top:0px; z-index:6;">' +
    		'<table width="100%" height="100%" cellspacing=0 cellpadding=0>'+
    			'<tr valign="middle"><td align="center">';
    if (!noX){
    		htm+='<table class="'+class1+'" cellspacing=0 cellpadding=0 style="width:100px;">';
    		var im1='/images/xsymb.gif';
    		var im2='/images/xsymbred.gif';
    		htm+='<tr style="height:20px;"><td style="padding-right:10px; padding-top:10px; padding-left:10px;">' +
    				'<table cellspacing="0" cellpadding="0" width=100%><tr><td class="popupwindowtitle '+class2+'" width="100%">'+title+'</td><td style="text-align:right; padding-left:10px;">'+
    				'<table cellspacing="0" cellpadding="0" class="'+class1+'" height="100%"><tr><td style="padding:1px;">' +
    				'<img onMouseOver="this.src=\''+im2+'\'" onMouseOut="this.src=\''+im1+'\'" onClick="'+func+'" src="'+im1+'" class=\"imgheight\">' +
    				'</td></tr></table>' +
    				'</td></tr></table></td></tr>'; 
    		htm+='<tr><td style="padding-top:10px; padding-left:10px; padding-bottom:10px; padding-right:10px"><table class="'+class2+'" cellspacing="0" cellpadding="0" width="100%"><tr><td height="48px" ><div id=\'popupcontentparent\'><div style=\'display:block\' id=\'popupcontent\'> </div> </div></td></tr></table></td></tr>';
    		//htm+='<tr><td style="padding-right:10px; padding-left:10px; padding-bottom:10px;"><table cellspacing=0 cellpadding=0 width=100% class="popupwindowtitle '+class2+'"><tr><td>'+popfooter+'</td></tr></table></td></tr></table>';
    		htm+='<tr><td style="padding-right:10px; text-align:right; padding-left:10px; padding-bottom:10px;">'+popfooter+'</td></tr></table>';
    }
    else{	htm+='<table width="100%" class="popupwindowtablesimple" cellspacing="0" cellpadding="0"><tr><td>'+text+'</td></tr></table>'; }
	htm+=    '</td></tr>' +	
    		'</table>' +
    	'</div>';
	//htm+= '</div>';
    img.innerHTML=htm; 
    img.style.visibility='Visible';

	/*
	$(img).css('display','none');
	$(img).css('visibility','visible');
	if(!noX ) { $(img).fadeOut('normal', function(){ $(img).fadeIn('slow'); }); }
	*/
	
	/*
    try{
	    window.document.roomflash.focus();
	}
	catch(Exception){}
	*/

	/* REMOVE WSS JUNK */
	text = text.replace(/<menu[^>]*>/gi,'<!-- <menu>');
	text = text.replace(/<\/menu>/gi,'</menu> -->');

	$("#popupcontent").html(text);
	$("#popupcontent").show(1000, function() { checkHeight("popupcontent",80); });

}


function checkHeight( content, offset )
{
	if ( $("#"+content).height() > ( $(window).height() - offset ) )
	{
		$("#"+content).animate({ height: ($(window).height() - offset ) }, function()
		{
			$("#"+content).css( "overflow-y", "scroll" );
		});
	}
}

function showPopImG(text,noX)
{
	var img;
    if (document.all){ img = document.getElementById(popupdivImIE); }
  	else { img = document.getElementById(popupdivIm); }
	__showPop(text,noX,img,'hideTheImage()','popupwindowtable2','popupwindowinnertable2','');
}


function showPopIm(text,noX,title)
{
	var img;
    if (document.all){ img = document.getElementById(popupdivImIE); }
  	else { img = document.getElementById(popupdivIm); }
	_showPop(text,noX,img,'hideTheImage()',title);
}

function showPop(text,noX,title)
{
	var img;
	if(secondlayer)
	{
		if (document.all){ img = document.getElementById(popupdivIE2); }
	  	else { img = document.getElementById(popupdiv2); }
	  	_showPop(text,noX,img,'hideThePop2()',title);
	}
	else
	{
	    if (document.all){ img = document.getElementById(popupdivIE); }
	  	else { img = document.getElementById(popupdiv); }
		_showPop(text,noX,img,'hideThePop()',title);
	}
}


function _writeOnDiv(text,divid)
{
 	_doTheRest(divid,text);
}


function _doTheRest(div,tex)
{
	//insertJscript(tex);
	//img = document.getElementById(div);
	//img.innerHTML=tex;
	$("#"+div).html(tex);
    if ( (new String(tex)).search(/myscrollbar/)!=-1 )
    { 
	    if ( (new String(tex)).search(/myscrollbar2/)!=-1 )
	    { 
	    	zxcVerticalScroll('myscrollbar2','textcontent2','mousedown',10);
	    }
	    zxcVerticalScroll('myscrollbar','textcontent','mousedown',10);
	}
}


function writeOnDiv(text)
{
 	_writeOnDiv(text,'secondeffdiv');
}



function showXMLHTTPOnDiv(remotepage,ispopup)
{
	_showXMLHTTPOnDiv(remotepage,ispopup,'secondeffdiv','');
}

function showXMLHTTPOnDivWithTitle(remotepage,ispopup,title)
{
	_showXMLHTTPOnDiv(remotepage,ispopup,'secondeffdiv',title);
}

      
function _showXMLHTTPOnDiv(remotepage,ispopup,divid,title)
{
	__showXMLHTTPOnDiv(remotepage,ispopup,divid,false,title)
}


function __showXMLHTTPOnDiv(remotepage,ispopup,divid,reload,title)
{
	if (ispopup){ showThePopWithoutX('/images/loader2.gif'); }
	else 
	{ 
		_writeOnDiv('<table width="100%" height="100%" cellspacing=0 cellpadding=0 style="border:1px #dddddd solid;">' + 
		'<tr valign="middle"><td align="center">' +
		'<img border=0 src="/images/loader.gif">' +
		'</td></tr></table>',divid); 
	}
	if(reload)
	{
		var date = new String(''+(new Date().getTime()));
		date = date.substring(date.length-7,date.length-1);
		var params = 'silly=' + date;
		
	    var s= (new String(remotepage)).replace(/silly=[0-9]{6}/g,params);
	    if (s==remotepage)
	    { 
	    	if ( (new String(remotepage)).search(/\?/)==-1 ){ remotepage+='?'+params; }
	    	else { remotepage+='&'+params; } 
	    }
	    else { remotepage=s; }
    }
    
	var divpar = 'divid=' + divid;
	var st= (new String(remotepage)).replace(/divid=[a-zA-Z0-9]+/g,divpar);
	if (new String(remotepage).search(/divid=[a-zA-Z0-9]+/)==-1)
	{ 
	  	if ( (new String(remotepage)).search(/\?/)==-1 ){ remotepage+='?'+divpar; }
	   	else { remotepage+='&'+divpar; } 
	}
	else {remotepage=st; }

	f = function(xData,status)
	{
		if (status == 'success') 
		{
			if (ispopup){ showPop(xData.responseText,false,title); }
			else { _writeOnDiv(xData.responseText,divid); }
		}
		else if(ispopup){ hideThePop(); }
	};

	$.ajax({
		url: remotepage,
		type: "GET",
		dataType: "html",
		complete: f
	});

}

$(document).ready(function()
{
	var dscroll = window.onscroll
	window.onscroll = function() { if(dscroll){ dscroll(); } moveTheDiv();  }
});

