

/* SYSTEM */

function debug(text) {
  ((window.console && console.log) ||
   (window.opera && opera.postError) ||
   window.alert).call(this, text);
}

var gl = null; 

$(document).ready(function(){

	// Link
   $('a[href^=http]').click( function() { window.open(this.href); return false;  }); 
   $('a[href*=files]').click( function() { window.open(this.href); return false;  });
   
   
   // Resize Co Pos
   $(window).resize(function() {

	   wh = parseInt($(this).height()) / 2;
	   ph = 280; new_pos = wh - ph; 
	   
	   if(new_pos < 20 ) {  new_pos = 20; }
	   $('.placeholder').css({"margin-top":new_pos + "px", "top":"0px"});
	   
   }).trigger("resize");  

	// Spamm 
   var a = document.getElementsByTagName("a");
   for (var i = a.length-1; i >= 0; i--) { if (a[i].className.search(/\bemail\b/) != -1) { var email = a[i].firstChild.data + "@" + a[i].lastChild.data; a[i].innerHTML = email; a[i].href = "mailto:" + email;  }}  
     
	if($('.slGal').size() && $('.slProjector').size()) { 
		
		$('.slGal').find('a').click(function() { 
			img = $(this).attr("href");
			
			$('.slGal').find('a').removeClass("active");
			$(this).addClass("active"); 
			
			$('.slProjector .view_port').css({"background-image":"url("+img+")"}).attr("index", $(this).parents("li").index());
			if($(this).attr("original-title") != "") {   
				$('.slProjector .info .description').html($(this).attr("original-title")).show();
			} else {
				$('.slProjector .info .description').hide();
			}
			return false;		
		
		}).tipsy().eq(0).each(function() {
			
			img = $(this).attr("href");
			$(this).addClass("active"); 
			$('.slProjector .view_port').css({"background-image":"url("+img+")"}).attr("index", $(this).parents("li").index());
			//$('.slProjector .info .description').html($(this).attr("original-title"));  	
			if($(this).attr("original-title") != "") {   
				$('.slProjector .info .description').html($(this).attr("original-title")).show();
			} else {
				$('.slProjector .info .description').hide();
			}
			
		
		}); 
		
		$('.slProjector .view_port').click(function() {
			$(".gl_fb a").eq($(this).attr("index")).trigger("click");
		}); 
		
		
		$(".gl_fb a").fancybox({
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'titlePosition' 	: 'inside', 
			'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
				if(lang == 0) { 
				return '<span id="fancybox-title-over">Bild ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
				} else { 
				return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
				}
			}
		});
	
	}
	
	$('.gal-list').each(function() { 
		var gl_list = $(this); 	gl_list.find("a").hide(); gl_list.find("li").mouseenter(function() { li = $(this); li.addClass("hover");	li.find("a").show(); }).mouseleave(function() { li = $(this); li.find("a").hide();	li.removeClass("hover"); });
	});


});


