var ie=(document.all)?true:false;
var ns=(document.layers)?true:false;
var oNewWindow;

/****************************************************************************
 *  		INIT_FUNCTION
 ****************************************************************************/
$(function() {
 	
 	/* thickbox -> fancybox */
 	$(".tbox").each(function(){
 	
 	   var url=$(this).attr('href');
	   var baseURL;
	   if(url.indexOf("?")!==-1)
	   { 
		   baseURL=url.substr(0, url.indexOf("?"));
	   } else { 
	   	   baseURL=url;
	   }

	   var urlString = /\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$/;
	   var urlType = baseURL.toLowerCase().match(urlString);
	   
		if(urlType == '.jpg' || urlType == '.jpeg' || urlType == '.png' || urlType == '.gif' || urlType == '.bmp')
		{
		
			$(this).fancybox({
				'autoScale'	 : true,
				'titleShow' : false,
				'titlePosition' : 'over'
		 	});
		 	
		} else {
			
			var queryString = url.replace(/^[^\?]+\??/,'');
			var params = tb_parseQuery( queryString );
			
			FB_WIDTH = (params['width']*1) || 800;
			FB_HEIGHT = (params['height']*1) || 600;
			
			if(url.indexOf('TB_iframe') != -1)
			{
				$(this).fancybox({
					'width' : FB_WIDTH,
					'height': FB_HEIGHT,
					'href'  : url,
					'type'	: 'iframe',
					'padding' : 10,
					'autoDimensions' : false
			 	});
			} else {
				$(this).fancybox();
			}
		}
		
 	});
});

//------------------------------------------------------------------
function openNewWindow(URLtoOpen, windowName, windowFeatures) 
{ 
	newWindow=window.open(URLtoOpen, windowName, windowFeatures); 
}
//------------------------------------------------------------------
function toggleVisibility(me)
{
	if (me.style.display=="block")
	{
		me.style.display="none";
	}else {
		me.style.display="block";
	}
}
//------------------------------------------------------------------
function popup(URLtoOpen,Width,Height,Scroll) 
{ 	
    var myWidth = 0, myHeight = 0;
      
	if( typeof( window.innerWidth) == 'number' ) 
	{
	    //Non-IE
	    myWidth = window.innerWidth;
	    myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	    //IE 6+ in 'standards compliant mode'
	    myWidth = document.documentElement.clientWidth;
	    myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	    //IE 4 compatible
	    myWidth = document.body.clientWidth;
	    myHeight = document.body.clientHeight;
	}
		
	x=(myWidth/2)-(Width/2);	
	y=(myHeight/2)-(Height/2);	
	
	newWindow=window.open(URLtoOpen,'Popup','scrollbars='+Scroll+',width='+Width+',height='+Height+',top='+y+',left='+x);
}
//------------------------------------------------------------------
function Blank(href)
{
	window.open(href,'_blank');
	return false;
}
//------------------------------------------------------------------
function tb_parseQuery ( query )
{
   var Params = {};
   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 ReplaceFoto(foto,preview)
{
	document.getElementById('PwFoto').src=foto;
	document.getElementById('PwFoto').alt=foto;
	document.getElementById('PwPreviewFoto').href=preview;
	document.getElementById('PwPreviewLink').href=preview;	
}
