
var loaded=false;
var imageObjectList;
var imageList;

function checkBrowserName(name){
	   var agent = navigator.userAgent.toLowerCase();
	   if (agent.indexOf(name.toLowerCase())>-1) {
	     return true;
	   }
	   return false;
	 }

var currentPic=0;
var nextPic=1;

function changehighlight()
{	
	
	$(imageList[currentPic]).fadeOut(2000);
	$(imageList[nextPic]).fadeIn(2000);
	currentPic=nextPic;
	if(nextPic<imageList.length-1)
	{
		nextPic++;
	}
	else
	{
		nextPic=0;
	}
}

function bookmarksite(title, url) {
	if (document.all) {
		window.external.AddFavorite(url, title);
	} else if (window.sidebar) {
		window.sidebar.addPanel(title, url, '');
	}
}

function setTitle(element)
{
	element.title=element.rel;
}

function do_event_track(object)
{
	if(typeof(pageTracker)=="object")
	 {
		var pathinfo=object.src;
		pathinfo=pathinfo.split("/");
		pageTracker._trackEvent(pathinfo[pathinfo.length-2],'click',pathinfo[pathinfo.length-1]);
	 }
	 else
	 {
		return false; 
	 }
	
}

var Trackingarray=new Array('download');
function do_link_track(object)
{
	if(typeof(pageTracker)=="object")
	 {
		var pathinfo=object.href;
		pathinfo=pathinfo.substr(0,pathinfo.length-1);
		pathinfo=pathinfo.split("/");
		var paramindex=pathinfo.length-1;
		pageTracker._trackEvent('WP-link','click',pathinfo[paramindex]);
	 }
	 else
	 {
		return false; 
	 }
	
}

var api;

	
$(document).ready(function(){



	var image_overlay=$("<div></div>");
	var image_in_overlay=$('<img>');
	image_in_overlay.attr('id','image_in_overlay');
	image_overlay.attr('id','image_overlay').css('display','none');
	$(image_in_overlay).appendTo($(image_overlay));
	$(image_overlay).appendTo($("body"));
	$(".show_pictures").click(function(e)
			{
				e.preventDefault();
				$("#image_in_overlay").attr('src',$(this).attr('rel'));

					$("#image_in_overlay").load(function()
							{
								api=$("#image_overlay").overlay({closeOnClick:true,
																				api:true,
																				expose: '#f1f1f1',
																				onClose: function(){
																							$(".flash_container").css("visibility","visible");				
																					},
																					onBeforeLoad: function() {
																						$(".flash_container").css("visibility","hidden");
																				        }
							});
								api.load();
								$('body').bind('click',function(){api.close();$("body").unbind('click');});
							});
				
			}
		);
	
	if ( $('#teaserContent1').length )
	{
		imageObjectList=$(".highlight").find("div.highlightLayer");
		imageList=jQuery.makeArray(imageObjectList);
		if(typeof(teaserInterval)!='number')
		{
			teaserInterval=5000;
		}
		var highlightTimer=window.setInterval('changehighlight()',teaserInterval);
	}
	
	if ( $('#gallery').length==1 &&  $('.thumbnails a').length>0)
	{
	// select the thumbnails and make them trigger our overlay 
	$(".overlay_thumbs a").overlay({ 
	 
	    // each trigger uses the same overlay with the id "gallery" 
	    target: '#gallery', 
	 
	    // optional exposing effect 
	    expose: '#f1f1f1' ,
	    zIndex:10000,
		onBeforeLoad: function() {
		$(".flash_container").css("visibility","hidden");
		$("#mr").css("visibility","hidden");
		$(".overlay_thumbs a").each(function (e) {
          this.title=this.rel;
        });
		
		},
		onClose: function(){
				$(".flash_container").css("visibility","visible");	
				$("#mr").css("visibility","visible");				
		},
		onBeforeClose: function() {
			$(".overlay_thumbs a").each(function (e) {
		          this.title="";
		        });
				}
	 
	 
	// let the gallery plugin do its magic! 
	}).gallery({ 
		imgId:'gallery_img',
	    // the plugin accepts its own set of configuration options 
		template:'<strong>${title}</strong> <span>Image ${index} of ${total}</span>',
	    speed: 400 
	});
	
	$("a.prev,a.next").click(function()
			{
				$("#gallery_img").load(function(e)
						{	
							$("#gallery_img").unbind("load");						
							do_event_track(this);						
						});
				});
	$("img.thumb_event").click(function(e)
			{
				do_event_track(this);		
				
				});
	}
	$(".box_text a").click(function(e)
			{
				do_link_track(this);	
		});
	$('.movie_overlay_link').click(function()
			{
				var linkTo=$(this).attr('rel');				
			    $('#movie_overlay').find('param:eq(0)').val(linkTo);
			    $('#movie_overlay').find('embed').attr('src', linkTo);
			    $('#movie_overlay object').hide().show();
			    $('#movie_overlay').exposeIt();
			    
			    //var expLayer=$('<div id="exposeLayer" style="height:100%;width:100%;background-color: white;filter:alpha(opacity=90);-moz-opacity:0.9;-khtml-opacity: 0.9;opacity: 0.9;display:block;z-index:10000;position:absolute;top:0px;left:0px;"></div>');
	
			})
	}); 
var expLayer=$('<div id="exposeLayer" style="background-color: white;filter:alpha(opacity=90);-moz-opacity:0.9;-khtml-opacity: 0.9;opacity: 0.9;display:block;z-index:10000;position:absolute;top:0px;left:0px;"></div>');
jQuery.fn.exposeIt = function() {
	var o = $(this[0]);
	expLayer.css('height',$('body').height()+'px').css('width',$('body').width()+'px');
	expLayer.appendTo('body');
	o.css('z-index',100001);
	o.fadeIn(function(){
    	$('#exposeLayer').bind('click',function(){
    		o.fadeOut(function(){
    			$('#exposeLayer').remove();
    		});  	

    	});
	});	
};


