/********************************************************************/
// vars
/********************************************************************/

var sExpressInstall = "web/pix/expressInstall.swf";

/********************************************************************/
// general functions
/********************************************************************/

// address flash movie for external interface in action script
function thisMovie( movieName )
{
    if ( navigator.appName.indexOf("Microsoft") != -1 )
    {
        return window[movieName];
    }
    else
    {
        return document[movieName];
    }
}


/********************************************************************/
// AUSTAUSCH des Flash-Movies
/********************************************************************/
function loadSWF(file) {
	if (document.getElementById("keyvisual")) {
		location.hash = "#nav";
		swfobject.getObjectById("keyvisual").loadSWF(file);

	}
}
/********************************************************************/
//FAQ
/********************************************************************/
var activeFaq = null;

function showFaq ( layerId )
{
	if ( document.getElementById( layerId ) )
	{
		selectedFaq = document.getElementById( layerId );
		if ( selectedFaq.style.display == "block" )
		{
			selectedFaq.style.display = "none";
			activeFaq = null;
		}
		else if ( activeFaq != selectedFaq )
		{
			if ( activeFaq != null )
			{
				activeFaq.style.display = "none";
			}
			selectedFaq.style.display = "block";
			activeFaq = selectedFaq;
		}
	}
}

/********************************************************************/

$(document).ready(function(){

	// as long as we cannot rely on CSS2.1
	$("ul li:first-child").addClass("first");

	// navigation slideout effect
	var nav = $("#nav"), navhead = $("#navhead"), navtoc = $("#navtoc");
	var navAnimated = false;

	function toggleAnimated() {
		navAnimated = !navAnimated;
	}

	navtoc.hide();
	var applets = $("object[type=application/x-java-applet], object[classid=clsid:8AD9C840-044E-11D1-B3E9-00805F499D93]");

	navhead.click(function() {
		if (navAnimated) { return false; }

		toggleAnimated();
		navhead.toggleClass("open");
		applets.toggleClass("invisible");
		navtoc.slideToggle(250, toggleAnimated);

		return false;
	});


	nav.hoverIntent({
		timeout:1000,
		over : function() {
			if (navAnimated) { return false; }
			toggleAnimated();
			navhead.addClass("open");
			applets.addClass("invisible");
			navtoc.slideDown(250, toggleAnimated);
		},
		out : function() {
			if (navAnimated) { return false; }
			toggleAnimated();
			navhead.removeClass("open");
			applets.removeClass("invisible");
			navtoc.slideUp(250, toggleAnimated);
		}
	});

	// Top navigation dropdowns
	$("#topnav .dropdown ul").hide();
	$("#topnav .dropdown > a ").click(function(ev){
		$(this).blur();
		ev.preventDefault();
		if ($(this).parent("li").is(".open")) {
			$(this).parent("li").removeClass("open");
			$(this).parent("li").children("ul:first").slideUp(250);
		} else {
			$(this).parent("li").addClass("open");
			$(this).parent("li").children("ul:first").slideDown(250);
		}
	});
	$("#topnav .dropdown").hoverIntent({
		timeout:500,
		over:function(){},
		out:function(){
			if ($(this).is(".open")) {
				$(this).removeClass("open");
				$(this).children("ul:first").slideUp(250);
			}
		}
	});

	// Fanout lists
	$("ul.fanout h3:not(.open) + ul").hide();
	$("ul.fanout h3").click(function(ev){
		$(this).blur();
		ev.preventDefault();
		if($(this).is(".open")){
			$(this).removeClass("open");
			$(this).next("ul").slideUp(250);
		} else {
			$(this).addClass("open");
			$(this).next("ul").slideDown(250);
		}
	});

	// News navigation
	var itemHeight = 0;
	$("#newsnavitems li").
		each(function() {
			if ($(this).height() > itemHeight) {
				itemHeight = $(this).height();
			}
		}).
		css({height:itemHeight});

	var itemCount = $("#newsnavitems li").length;
	if (itemCount > 3) { itemCount = 3; } else { $("#newsnavtop div").hide(); }
	var itemActive = $("#newsnavitems li").index($("#newsnavitems .active").eq(0));
	$("#newsnavitems").jCarouselLite({
	        scroll: 1,
	        circular: false,
	        btnNext: "#newsnavnext",
	        btnPrev: "#newsnavprev",
	        vertical: true,
	        mouseWheel: true,
	        visible: itemCount,
	        start: (itemActive < itemCount) ? 0 : itemActive - itemCount + 1
	});


	$("body").addClass("jsenabled");

	// Box Form
	$("#contactFormBox").bind("submit", function() {
		var that = $(this);
		var button = this.getElementsByTagName("button")[0];

		var query = that.serialize();
		query += "&" + encodeURIComponent(button.name) + "=" + encodeURIComponent(button.value);

		jQuery.post(this.action, query, function(response) {
			var d = document.createElement('div');
			d.innerHTML = response;
			var container = $("#content .final.colbox", d);
			container.find(".col1, .col2, .col4, .col6").removeClass("col1, col2, col4, col6");

			var h1 = container.find("h1");
			h1.wrapInner("<h4/>").replaceWith(h1.children(":first"));
			that.replaceWith(container);
		});

		return false;
	})
});

jQuery(function() {
	var applicationForm = document.getElementById("form-application");
	if (!applicationForm) { return; }

	$(":file:last", applicationForm).one("change", function() {
		var p = $(this).parents("li:first").eq(0);
		p.after(p.clone(true)).
			next().find(":file").
				val("").one("change", arguments.callee);
	});
});


/********************************************************************/
//SHOP Deletebutton im Warenkorb
/********************************************************************/
$(document).ready(function(){
	jQuery('a[rel=delete]').bind("click",function(event){
		var row = $(this).parent().parent();
		row.fadeOut(600, function(){
			$(this).remove();
			$('form#webshop_basket_form').submit();
		});
		return false;
	});
});
