/**************************************************************
Ajax
//-----------------------------------------------------------*/
var xmlHttp;
function ajaxPageToContainer(url,contID){
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		alert('This method not supported. Please disable your javascript.');
		return;
	}
	xmlHttp.onreadystatechange=function(){
			if(xmlHttp.readyState==4 || xmlHttp.readyState=='complete'){
				loadAjaxReturn(contID);
			}
		}

	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function loadAjaxReturn(contID){
	document.getElementById(contID).innerHTML=xmlHttp.responseText;
	if (document.getElementById('lightbox')) {
		$("#lightbox").css("height","auto");
		$(function(){$('form.jNice').jNice();	});
	}
}

function GetXmlHttpObject(){ 
	var objXMLHttp=null
	if (window.XMLHttpRequest){
		objXMLHttp=new XMLHttpRequest()
	}
	else if (window.ActiveXObject){
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
}
//-----------------------------------------------------------






function loadHtml(width,ajax) {
	document.getElementById("lightbox").innerHTML = "<span class='xWindow' id='xWindow' style='pointer: cursor;' onclick='hideLightbox();'></span><div id='lightBoxContent'></div>";
	if (ajax.indexOf("iframe:")==0) {
		var url = ajax.substr(7);
		document.getElementById("lightBoxContent").innerHTML = "<iframe width='100%' height='100%' frameborder='0' src='"+url+"'></iframe>";
	}
	else if (ajax.indexOf("video:")==0) {
		var url = ajax.substr(6);
		//document.getElementById("lightBoxContent").innerHTML = "<iframe width='100%' height='100%' frameborder='0' src='"+url+"'></iframe>";
		//document.getElementById('lightBoxContent').innerHTML = url;
		
		// newSwfObj("/"+url);
		newQT("/"+url);
	} else {
		ajaxPageToContainer(ajax,'lightBoxContent');
	}
}
function newQT(url) {
	document.getElementById('lightbox').style.width = "700px";
	document.getElementById('lightbox').style.height = "415px";
	var marLeft = parseInt(document.getElementById('lightbox').style.marginLeft);
	var newMarLeft = marLeft-32;
	document.getElementById('lightbox').style.marginLeft = newMarLeft+"px";
	var qt = '<object height="380" width="650" id="" codebase="http://www.apple.com/qtactivex/qtplugin.cab#version=7,3,0,0" classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" class="quicktime">';
		qt+= '<param value="'+url+'" name="src">';
		qt+= '<param value="false" name="showlogo">';
		qt+= '<param value="tofit" name="scale">';
		qt+= '<param value="true" name="saveembedtags">';
		qt+= '<param value="true" name="postdomevents">';
		qt+= '<embed height="380" width="650" src="'+url+'">';
		//qt+= '<param value="http://trailers.apple.com/trailers/global/elements/quicktime/qt_endstate640x400.jpg" name="posterframe">';
		qt+= '<param value="false" name="showlogo">';
		qt+= '<param value="true" name="autostart">';
		qt+= '<param value="true" name="cache">';
		qt+= '<param value="white" name="bgcolor">';
		qt+= '<param value="false" name="aggressivecleanup">';
		qt+= '</object>';
	document.getElementById('lightBoxContent').innerHTML = qt;
}
function lightBox(width,height,ajax) {
	GLOBAL_SLIDESHOW_ON = false;
	if (!width){width=800;}
	if (!height){height=400;}
	if (!document.getElementById('lightbox')) {
		var newdiv = document.createElement('div');
		newdiv.setAttribute('id', 'lightbox');
		newdiv.className 		= 'floatingDiv';
	
		var bodyWidth 		= document.body.clientWidth;
		var screenWidth		= screen.width;
		if (bodyWidth>screenWidth){newWidth=screenWidth;}else{newWidth=bodyWidth;}
	
		if (!(BrowserDetect.browser=="Explorer" && BrowserDetect.version <= 7)) {
			newdiv.style.marginLeft	= parseInt((newWidth/2)-20)+"px";
		}
		document.body.appendChild(newdiv);
	}
	var obj = document.getElementById('lightbox');
	var yScroll 		= parseInt(document.body.scrollTop)|| parseInt(document.documentElement.scrollTop);
	obj.style.top 		= 80+parseInt(yScroll)+"px";
	obj.style.left		= 'auto';
	if (BrowserDetect.browser=="Explorer" && BrowserDetect.version <= 7) {
		obj.style.left		= (parseInt((document.body.clientWidth / 2) - (width /2)))+'px';
		obj.style.marginLeft= '0'; obj.style.marginRight= '0'; obj.style.marginTop= '0'; obj.style.marginBottom= '0';
	}
	if (document.all) { // Internet Explorer
		var screenWidth = document.body.clientWidth;
		var screenHeight = document.body.clientHeight;
	} else { // FF, Opera etc.
		var screenWidth = window.innerWidth;
		var screenHeight = window.innerHeight;
	}
	var newScreenWidth 	= parseInt((screenWidth/2) -(width/2));
	if (BrowserDetect.browser=="Explorer" && BrowserDetect.version <= 7) {
		newScreenWidth = 15;
	}
	//alert(newScreenWidth+"\n\r");
	$("#lightbox").animate({
		"width": width,
		"height": height,
		"marginLeft": (newScreenWidth-15)
	},500,function(){
		loadHtml(width,ajax);
	});
	bodySheet('show',width,ajax);
}

function bodySheet(action,width,ajax) {
	if (!document.getElementById('bodySheet')) {
		var newdiv = document.createElement('div');
		newdiv.setAttribute('id', 'bodySheet');
		document.body.appendChild(newdiv);
	}
	var bodyHeight 		= document.body.clientHeight;
	var screenHeight	= screen.height;
	if (bodyHeight > screenHeight) {
		overlayHeight = bodyHeight;
	} else {
		overlayHeight = screenHeight;
	}
	var obj = document.getElementById('bodySheet');
		if (action=='show') {
			obj.style.top = "0";
			obj.style.height = "1px";
			obj.style.left	 = "auto";
			$("#bodySheet").animate({
				"height" : overlayHeight
			},500)
			//obj.style.top = "0";
			//obj.style.height = overlayHeight+"px";
			//obj.style.left	 = "auto";
			//loadHtml(width,ajax);
		} else {
			$("#bodySheet").animate({
				"height" : 0
			},500,function(){
				document.getElementById("bodySheet").style.left = "-999em";
			})
			//obj.style.height = "0px";
			//obj.style.left	 = "-999em";
		}
}

function hideLightbox() {
	bodySheet('hide');
	if (document.getElementById('lightbox')) {
		document.getElementById('xWindow').style.display = 'none';
		document.getElementById('lightBoxContent').innerHTML = '';
		var bodyWidth 		= document.body.clientWidth;
		var screenWidth		= screen.width;
		if (bodyWidth>screenWidth){newWidth=screenWidth;}else{newWidth=bodyWidth;}
		$("#lightbox").animate({

			"marginLeft": (newWidth/2),
			"width": 0,
			"height": 0
		},500,function() {removeBox(document.getElementById('lightbox'));})
	}
}

function removeBox(lightbox) {
	lightbox.parentNode.removeChild(lightbox);
	//lightbox.style.left="-999em";
	GLOBAL_SLIDESHOW_ON = true;
}

function findLightBox() {
	lbs = getElementsByClassName(document,"a","lightbox");
	for(var i=0;i<lbs.length;i++) {
		lbs[i].onclick=function() {
			lightBox(725,360,this.href);
			return false;
		}
	}
}

$(document).ready(function() {
	findLightBox();}
);


