
/*************************************************** Externe Links vorbereiten */

function externalLinks() 
	{	
	if (!document.getElementsByTagName) return; 
 	var anchors = document.getElementsByTagName("a"); 
 	for (var i=0; i<anchors.length; i++)
		{ 
   		var anchor = anchors[i]; 
   		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "blank")anchor.target = "_blank"; 
		} 
	} 
	
/*************************************************** IE6 */

function handleIE6()
	{
	if($.browser.msie && $.browser.version<7)
		{
		var input = $("input[type='text']").addClass("ie6textinput");
		var textarea = $("textarea").addClass("ie6textinput");
		var password = $("input[type='password']").addClass("ie6textinput");
		}
	}

/*************************************************** cycle_slideshow */

function cycle_slideshow()
	{
	if($('.slideshow').length)
		{
		var slideshows = $('.slideshow').each(function(){
			if($(this).find('.element').length>1)
				$(this).cycle({slideExpr:'.element', timeout:6000, cleartype: true, cleartypeNoBg: true})
			});
		}
	}

/*************************************************** set & get Cookies */

function setCookie(name,value,days) 
	{
	if (days) 
		{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
		}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
	}

function getCookie(name) 
	{
	var name_eq = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) 
		{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(name_eq) == 0) return c.substring(name_eq.length,c.length);
		}
	return null;
	}

/*************************************************** ghostVal */

function ghostVal(el,txt)
	{
	
	$(el).attr('value',txt);
	$(el).data('txt',txt);
	
	if($(el).attr('type')=='password')
		{
		repField = "<input onfocus=\"replaceField(this,'"+$(el).attr('id')+"')\" type=\"text\" value=\""+txt+"\" id=\""+$(el).attr('id')+"\" style=\""+$(el).attr('style')+"\" maxlength=\""+$(el).attr('maxlength')+"\" name=\""+$(el).attr('name')+"\" />";
		orgField = "<input onblur=\"replaceField(this,'"+$(el).attr('id')+"')\" type=\"password\" value=\"\" id=\""+$(el).attr('id')+"\" style=\""+$(el).attr('style')+"\" maxlength=\""+$(el).attr('maxlength')+"\" name=\""+$(el).attr('name')+"\" />";
		
		$(el).replaceWith(repField);
		
		}
	else
		{
		$(el).bind('focus',function() 
			{ 
			if($(this).attr('value')==$(el).data('txt'))
				{
				$(this).attr('value',''); 
				}
			});
		$(el).bind('blur',function() 
			{ 
			if($(this).attr('value')=='')
				{
				$(this).attr('value',$(el).data('txt')); 
				}
			});
		}
	}

/************************* Shadowbox ******************************/

var sbTimer,sbBodyHeight,setHeight;

function reloadPage()
	{
	location.reload(true);
	}
	
function sbAutoHeight()
	{
	var body = $('body:first');
	var sbWrapper = $('#sb-wrapper');
	var sbWrapperInner = $('#sb-wrapper-inner');
	
	var _setHeight = function()
		{
		var bodyHeight = $(window).height();	
		var sbOuterHeight = sbWrapper.height();
		var _sbBodyHeight = sbBodyHeight+4;
		if(sbBodyHeight>bodyHeight-100)
			_sbBodyHeight=bodyHeight-100;
		var newYpos = parseInt((bodyHeight/2)-(sbOuterHeight/2));	
		
		sbWrapperInner.height(_sbBodyHeight);
		sbWrapper.css({'top':newYpos+'px'});
		}
	sbTimer = setInterval(_setHeight,50);
	}


function initShadowboxes()
	{
		
	Shadowbox.init({overlayColor:'#2c2c2e',overlayOpacity: 0.8, modal: true, skipSetup: true, onClose:function(){ reloadPage(); clearInterval(sbTimer); } });
	
	// Standard
	var stdOverlays = $('.shadowbox');
	if(stdOverlays.length) {
		stdOverlays.click(function(event){
			event.preventDefault();
			Shadowbox.open({
				player: 'iframe',
				content: url=$(this).attr('href'),
				width: 800,
				height: 600				
				});
			});
		}
		
	}

/************************* schriftersetzung mit cufon ******************************/

function cufonFontReplace()
	{
	//Cufon.replace('.loginregister .sep', { fontFamily: 'AntennaCond Regular' });
	}


/************************* Animations ******************************/

function animations(){
	var logo = $('.logo');
	/*logo.hover(function(){
			$(this).stop(true,true).animate({'padding-top':'44px'},500,"easeOutBounce");
		},function(){
			$(this).stop(true,true).delay(250).animate({'padding-top':'24px'},750,"easeOutCirc");
		}
	);*/
	$('#nav').find('a:not([class="active"])').hover(function(){
			$(this).stop(true,true).animate({'color':'#fff'},150);
		},function(){  
			$(this).stop(true,true).delay(250).animate({'color':'#9d9d9f'},500);
		}
	);
	$('#subnav').find('a:not([class="active"])').hover(function(){
			$(this).stop(true,true).animate({'color':'#000'},150);
		},function(){  
			$(this).stop(true,true).delay(250).animate({'color':'#58595b'},500);
		}
	);
	$('.black, button').hover(function(){
			$(this).stop(true,true).animate({'background-color':'#414042'},150);
		},function(){
			$(this).stop(true,true).delay(250).animate({'background-color':'#000'},500);
		}
	);
	
}

/************************* animted Portfolio ******************************/

function animatedPortfolio(){
	
	if($('#content .gallerylist').length) {
		$('#content').find('.padder').prepend('<div id="ajaxcontent" />');
		var ajaxContent = $('#ajaxcontent');
		var numItems = $('.gallerylist').find('li').length;
	}
		
	$('#content .gallerylist').find('a').each(function(idx){ 
		$(this).attr('hash', idx);									  
		$(this).click(function(event){
			event.preventDefault();
			var href = $(this).attr('href');
			ajaxContent.css({'opacity':0});
			$('#media').remove();
			$(location).attr("hash", $(this).attr("hash"));
			
			ajaxContent.load(href+' #media', function(){
				var settingsCont = $('#settings')
				if(settingsCont.length) {
					var properties = settingsCont.html().split(', ');
					settingsCont.remove();
					var settings = {};
					properties.forEach(function(property) {
						var tup = property.split(':');
						settings[tup[0]] = tup[1];
					});
					var flashvars = {
						file:settings.swfFile,
						image:settings.swfImage,
						backcolor:'ffffff', frontcolor:'000000', lightcolor:'000000', screencolor:'ffffff', controlbar:'over', autostart:'false', dock:'false'						
					};
					var params = { allowfullscreen:'true', allowscriptaccess:'always', wmode:'opaque' };
					swfobject.embedSWF(settings.swfPlayer, "mediaspace"+settings.swfMediaspace, settings.swfWidth, settings.swfHeight, "9.0.0","expressInstall.swf", flashvars, params);
				}
				
				var mediaHeight = parseInt($('#media').find('object,img').height())+parseInt($('#media').css('margin-bottom'))+parseInt($('#media').find('figcaption').height())+parseInt($('#media').find('figcaption').css('margin-top'));
				if(mediaHeight<410) mediaHeight=mediaHeight+25;
				
				ajaxContent.css({'height':mediaHeight+'px'});
				
				var figCaption = $('#media').find('figcaption');
				ajaxContent.animate({'opacity':1},500);
				figCaption.slideUp(0).delay(750).slideDown(250);
				if(typeof(addthis)=='undefined')$.ajax({ url:'//s7.addthis.com/js/250/addthis_widget.js', dataType:'script', complete:function(){ addthis.init(); }});
				else addthis.toolbox('#addthis');
				
			});			
		});		
	});
	
	var hash = $(location).attr("hash").slice(1);
    if(hash)
		$("#content .gallerylist").find('a').eq(hash).click();
}

/*************************************************** Funktionsaufrufe */

$(document).ready(function(){
	externalLinks();
	handleIE6();
	animations();
	//animatedPortfolio();
	
	$('.gallerylist').find('li:nth-child(3n)').css({'margin-right':0});

	var $buoop = {} 
		$buoop.ol = window.onload; 
		window.onload=function(){ 
		if ($buoop.ol) $buoop.ol(); 
		var e = document.createElement("script"); 
		e.setAttribute("type", "text/javascript"); 
		e.setAttribute("src", "files/js/buoop/buoop.js"); 
		document.body.appendChild(e); 
	} 	
});

