/* FUNCTIONS
------------------------------------------------------------------------------*/

/* OPEN GAL
------------------------------------------------------------------------------*/

function openGal(id){
	$("a[rel='gal"+id+"']").colorbox({maxHeight:'90%',maxWidth:'90%',open:true});
}


/* SCROLLING
------------------------------------------------------------------------------*/

$.easing.easeOutQuint = function(x, t, b, c, d) {
	var s=1.70158;var p=0;var a=c;
	if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
	if (a < Math.abs(c)) { a=c; var s=p/4; }
	else var s = p/(2*Math.PI) * Math.asin (c/a);
	return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
};



/* BOXES (TRANS HOVER)
------------------------------------------------------------------------------*/

$(function(){
	$('.teaser img').each(function() {
	    $(this).hover(function() {
	        $(this).stop().animate({ opacity: 1.0 }, 300);
	    },
	   function() {
	       $(this).stop().animate({ opacity: 0.7 }, 300);
	   });
	});
});


/* MAILTO
------------------------------------------------------------------------------*/

jQuery.fn.mailto = function() {
	return this.each(function(){
		var email = $(this).html().replace(/\s*\(.+\)\s*/, "@");
		$(this).before('<a href="mailto:' + email + '" rel="nofollow" title="E-Mail ' + email + '">' + email + '</a>').remove();
	});
};


/* BLANKWIN
/* written by Alen Grakalic, provided by Css Globe (cssglobe.com)
/* http://cssglobe.com/post/1281/open-external-links-in-new-window-automatically/
------------------------------------------------------------------------------*/

this.blankwin = function(){
	var hostname = window.location.hostname;
	hostname = hostname.replace("www.","").toLowerCase();
	var a = document.getElementsByTagName("a");
	this.check = function(obj){
		var href = obj.href.toLowerCase();
		return (href.indexOf("http://")!=-1 && href.indexOf(hostname)==-1) ? true : false;
	};
	this.set = function(obj){
		obj.target = "_blank";
		//obj.className = "external";
	};
	for (var i=0;i<a.length;i++){
		if(check(a[i])) set(a[i]);
	};
};



// script initiates on page load.

this.addEvent = function(obj,type,fn){
	if(obj.attachEvent){
		obj['e'+type+fn] = fn;
		obj[type+fn] = function(){obj['e'+type+fn](window.event );}
		obj.attachEvent('on'+type, obj[type+fn]);
	} else {
		obj.addEventListener(type,fn,false);
	};
};
addEvent(window,"load",blankwin);
