/* */
last = 0;
var autoplay = true;
// Delay Plugin for jQuery
// - http://www.evanbot.com
// - ﾃつｩ 2008 Evan Byrne
jQuery.fn.delay = function(time,func){
	this.each(function(){
		setTimeout(func,time);
	});
	return this;
};



// //

function dosizer() {
	var x,y;
	if (self.innerHeight) // all except Explorer
	{
		x = self.innerWidth;
		y = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	}
	if (x>=1140) { 
		$("#page").css("width",  "90%" );
		var me = ($("#page").width())-429;
		if (me>560) { 
			$("#middleCONTENT").css("width",  me+"px" );
		} 
	} else {
		$("#page").css("width",  "1000px" );
		$("#middleCONTENT").css("width",  "560px" );
	}
	// Produktübersicht Javascript zum Wegnehmen der Border
	getRidOfExtraClass()
}





function blend(i) {
	var dist = 793;
	if ( last == i)	 { return false; }

	function doreset(i) {
		$("#greenbox_" + (i+1)).css("left",  dist + "px" );
		$("#greenbox_" + (i-1)).css("left",  -dist + "px" );
	}

	if (last > i) {
		$("#greenbox_" + last).animate({"left": dist + "px"}, 750);
		$("#greenbox_" + i).css("left",  -dist + "px" );
		$("#greenbox_" + i).animate({"left": "0"}, 750, function () {
			doreset(i);
		});	
	}
	if (last < i) {
		$("#greenbox_" + last).animate({"left": -dist + "px"}, 750);
		$("#greenbox_" + i).css("left",  dist + "px" );
		$("#greenbox_" + i).animate({"left": "0"}, 750, function () {
			doreset(i);
	    });	
	}
	$("#greennavbut_" + i).addClass('navion');
	$("#greennavbut_" + last).removeClass('navion');
	last = i;

	//setTimeout('thewait()',4000);
}







function thewait(cond) {
    if (autoplay) {
        if (last<10) {
            var callme = last+1;
        } else {
            var callme = 1;
        }
        blend(callme);
        clearTimeout(mywait);
        mywait = setTimeout('thewait()',4000);
    }

}



//
//
//
// CHECK auf letztes Produkt unt entfernen von der entsprechenden Box
function getRidOfExtraClass() {
	// Alle ".test_produkt" classen objekte werden in "boxes" geladen
	var boxes = $.makeArray($(".test_produkt"));
	// einmal wird über das array iteriert zum feststellen der maxpos
	// get maxpos
	var maxpos = 0;
	$(boxes).each(function(int) {
		var c = $(this).position().left;
		if (maxpos<c) { maxpos = c; }
	});

	// ein zweites mal wird über das Array iteriert um die Klasse ohne Border hinzuzufügen
	// somit dem rechtesten Objekt den Border zu nehmen	
	// fuege klasse ohne rechten rand hinzu
	$(boxes).each(function(int) {
		if ($(this).position().left==maxpos) {
			$(this).addClass("test_box_NoRightBorder");
		} else {
			$(this).removeClass("test_box_NoRightBorder");
		}
	});
}







function iphone() {
	if(navigator.userAgent.match(/iPhone/i)){
		// weihnachtsaddon
		$("body").css("background-image","url(wp-content/themes/schluderbacher/_grfx/background.gif)");
		$("body").css("background-repeat","x-repeat");
	}
}






function greenBox() {
	$("#greenbox").hover(
        function() {
            autoplay = false;
            $("#content").stop().animate({ "opacity" : "0.7" }, 4000);
            //$("body").addClass("greenover");
        },
        function() {
            autoplay = true;
            clearTimeout(mywait);
            //mywait = setTimeout('thewait()',4000);
            thewait();
            $("#content").stop().animate({ "opacity" : "1" }, 500);
            // $("body").removeClass("greenover");
        }
    );
}






function addRosenmontag () {
	$("#kasten_3 .fliestext p:first" ).prepend("<b>ACHTUNG:<br />Rosenmontag geschlossen</b> <br />");
}





function addMitUnsKannMan() {
	$("#MitUnsKannManBox").hover(function(){
		$(this).animate( { "opacity":0.7 }, 300).css("cursor", "pointer");
	}, function(){
		$(this).animate( { "opacity":1 }, 300).css("cursor", "auto");
	});
	$("#MitUnsKannManBox").click(function(){
		$(".videobox").animate({ "marginLeft" : 0},1000);
		$(this).animate({ "marginLeft" : "3000px"},1000);
		src="Startseite";
		_gaq.push(['_trackEvent', 'MitUnsBox', 'Click', src]);

	})

}


function hidejobs() {
	$("a[title='Jobs']").closest("li").remove();
}



$(document).ready(function(){

	last = 1;
    mywait = setTimeout('thewait()',4000);
    greenBox();
    addMitUnsKannMan();
    hidejobs();
    //addRosenmontag();
	// dosizer();
});
