/*
 * Slightly Thickerbox 1.7
 * By Jason Levine (http://www.jasons-toolbox.com)
 * A modification of Thickbox by Cody Lindley (http://www.codylindley.com)
 * Under an Attribution, Share Alike License
 * Thickbox is built on top of the very light weight jquery library.
 */

var TB_WIDTH = 500, TB_HEIGHT = 500, TB_VisibleSelects, TB_WasOpen;

//add thickbox to href elements that have a class of .thickbox
function TB_init(){
	$("a.aurkibidea").click(function(){
	TB_ShowObj(this);
	//this.blur();
	return false;
	});
	$("a.pdf_textu").click(function(){
	TB_ShowObj(this);
	//this.blur();
	return false;
	});
	TB_WasOpen = false;
}


function TB_ShowObj(ThickObj) {
	var caption, url, thickgroup;
	try {
		caption = ThickObj.title || ThickObj.name || "";
		url = ThickObj.href;
		thickgroup = ThickObj.rel;
	
		if (document.getElementById("TB_overlay") == null) {
			$("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
			$("#TB_overlay").click(TB_remove);
		}
		//jabi$(window).resize(TB_position);
		//jabi$(window).scroll(TB_position);
		TB_position();
		
 		//$("#TB_overlay").show();
		//$("body").append("<div id='TB_load'><div id='TB_loadContent'><img src='images/circle_animation.gif' /></div></div>");
		
		var queryString = url.replace(/^[^\?]+\??/,'');
		var params = parseQuery( queryString );
		
		TB_position();
		ajaxContentW = TB_WIDTH - 30;
		ajaxContentH = TB_HEIGHT - 45;
		$("#TB_window").append("<div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton'>itxi</a></div><div id='TB_ajaxContent' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px;overflow:auto;'></div>");
		$("#TB_closeWindowButton").click(TB_remove);
		$("#TB_ajaxContent").load(url, function(){
			TB_position();
			//	$("#TB_load").remove();
			$("#TB_loadContent").show();
			TB_ShowBox();
		});
	} catch(e) {
		alert( e );
	}
}

function TB_ShowBox(Direction) {
	$("#TB_overlay").show();
	TB_VisibleSelects = $("select:visible");
	TB_VisibleSelects.toggle();
	$("#TB_overlay").show();
	$("#TB_window").show();
	$("#TB_window a.itzuli").click(function() {
				TB_remove();
				return false;
	});
	TB_WasOpen = true;
	
}

function TB_AnimationComplete() {
//		$("#TB_overlay").show();
		$("#TB_window").fxReset();
}

function TB_HideBox(Direction, LocalNextObjToShow) {
	TB_NextObjToShow = LocalNextObjToShow;
	$("#TB_window").hide();
	TB_HideBox_Part2();
}

function TB_HideBox_Part2() {
	$("#TB_window").remove();
	$("body").append("<div id='TB_window'></div>");
	TB_ShowObj(TB_NextObjToShow);
}

//helper functions below

function TB_remove() {
	// Interface Elements for JQuery are not included
	$("#TB_window").fadeOut("fast",function(){$('#TB_window,#TB_overlay').remove();});
	$("#TB_load").remove();
	TB_VisibleSelects.toggle();
	TB_WasOpen = false;
	return false;
	
}

function TB_position() {
	var pagesize = getPageSize();
  
  	if (window.innerHeight && window.scrollMaxY) {	
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		yScroll = document.body.offsetHeight;
  	}
	
	var arrayPageScroll = getPageScrollTop();
	
	$("#TB_window").css({width:TB_WIDTH+"px",height:TB_HEIGHT+"px",
	left: ((pagesize[0] - TB_WIDTH)/2)+"px", top: (arrayPageScroll[1] + ((pagesize[1]-TB_HEIGHT)/2))+"px" });
	$("#TB_overlay").css("height",yScroll +"px");

}

function parseQuery ( query ) {
   var Params = new Object ();
   if ( ! query ) return Params; // return empty object
   var Pairs = query.split(/[;&]/);
   for ( var i = 0; i < Pairs.length; i++ ) {
      var KeyVal = Pairs[i].split('=');
      if ( ! KeyVal || KeyVal.length != 2 ) continue;
      var key = unescape( KeyVal[0] );
      var val = unescape( KeyVal[1] );
      val = val.replace(/\+/g, ' ');
      Params[key] = val;
   }
   return Params;
}


function getPageScrollTop(){
	var yScrolltop;
	if (self.pageYOffset) {
		yScrolltop = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScrolltop = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScrolltop = document.body.scrollTop;
	}
	arrayPageScroll = new Array('',yScrolltop) 
	return arrayPageScroll;
}

function getPageSize(){
	var de = document.documentElement;
	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
	
	arrayPageSize = new Array(w,h) 
	return arrayPageSize;
}
