/**
 * @author Bilge Hauser
 * @date 02.05.2011
 * @company hier.com
 */

 
$(document).ready(function () {
	var sort_on;
	var page;
	sort_on = 'entries';
    page=0;

	jQuery.fn.center = function () {
	    this.css("position","absolute");
	    this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
	    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
	    return this;
	}
	// create custom animation algorithm for jQuery called "bouncy"
	$.easing.bouncy = function (x, t, b, c, d) {
	    var s = 1.70158;
	    if ((t/=d/2) < 1){ return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;}
	    return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
	}
	
	//$.tools.tooltip.addEffect("bouncy",
	//	// opening animation
	//	function(done) {
	//		this.getTip().animate({top: '+=15'}, 500, 'bouncy', done).show();
	//	},
	//	
	//	// closing animation
	//	function(done) {
	//		this.getTip().animate({top: '-=15'}, 500, 'bouncy', function()  {
	//			$(this).hide();
	//			done.call();
	//		});
	//	}
	//);
	//$("img[title]").tooltip();// {effect: "bouncy", opacity: 0.7, position: "top center"}
	$( ".detailLink_container, input:submit, .detailLink").button();

	if ($(".form_slider_button").length){
		$(".form_slider_button").click(function(event){
			if ($(".form-slider").length){
				event.preventDefault();
	           $('.form-slider').slideToggle('slow');
	       }		
		});
	}
	
	if ($(".gallery_slider_button").length){
		$(".gallery_slider_button").click(function(event){
			if ($(".gallery-slider").length){
			   event.preventDefault();
		       $(".gallery-slider").slideToggle('slow');		
	       }		
		});
	}
	
    // fading von elementen
	if ($(".fade01").length)
            $('.fade01').css("display","none");
	if ($(".fade02").length)
            $('.fade02').css("display","none");
	if ($(".fade03").length)
            $('.fade03').css("display","none");
	if ($(".fade04").length)
            $('.fade04').css("display","none");
	if ($(".fade05").length)
            $('.fade05').css("display","none");
	if ($(".fade06").length)
            $('.fade06').css("display","none");
	
    
    
    fade01();
	fade05();

    if ($("a.video_link").length){
        // install flowplayer into flowplayer container
        var player = $f("player", "/templates/default/player/flowplayer-3.2.7.swf", {
            //plugins: {
            //    controls: {
            //            url: '/templates/default/player/flowplayer-3.2.7.swf'
            //    }
            //},
            wmode: 'transparent',
            clip:  {
                autoPlay: true,
                autoBuffering: true
            }
        });
        $(".video_link[rel]").overlay({
            // use the Apple effect for overlay
            effect: 'apple',
            // when overlay is opened, load our player
            onLoad: function() {
                player.load();
            },
            // when overlay is closed, unload our player
            onClose: function() {
                player.unload();
            },
            mask: {
                color: '#000',
                loadSpeed: 200,
                opacity: 0.7
            }
        });
    }
    
});

// Popup
function NewWindow(mypage, myname, w, h, scroll ) {
	var winprops;
	var win;
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable';
	win = window.open(mypage, myname, winprops);
	if (parseInt(navigator.appVersion) >= 4) { win.focus(); }
}


function fade01() {
    if ($(".fade01").length && $(".fade02").length){
        $('.fade01').fadeIn(500,fade02);
    }else if ($(".fade01").length){
        $('.fade01').fadeIn(500);
    }
}

function fade02() {
    if ($(".fade02").length && $(".fade03").length){
        $('.fade02').fadeIn(500,fade03);
    }else if ($(".fade02").length){
        $('.fade02').fadeIn(500);
    }
}

function fade03() {
    if ($(".fade03").length && $(".fade03").length){
        $('.fade03').fadeIn(1000,fade04);
    }else if ($(".fade03").length){
        $('.fade03').fadeIn(1000);
    }
}

function fade04() {
    if ($(".fade04").length){
        $('.fade04').fadeIn(1000);
    }
}

function fade05() {
    if ($(".fade05").length && $(".fade05").length){
        $('.fade05').fadeIn(1000,fade06);
    }else if ($(".fade05").length){
        $('.fade05').fadeIn(1000);
    }
}

function fade06() {
    if ($(".fade06").length){
        $('.fade06').fadeIn(1000);
    }
}


