var check_loader = null;
var ac_index = 0;
var slides = new Array();

$(window).load(function() {
	if($.browser.msie) { init_canvas();	}					
});

$(document).ready(function() {
						   
	$("a.fancy").fancybox({
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic'
			});
						   
	if($.browser.msie) {
		init_ie();
	} else {
		init_browser();
		init_canvas();
	}
	
	init_searchfield();
	
	$("p").each(function() {
		$(this).addClass("hyphenate").addClass("text").attr("lang", "de");					 
	});
	
	Hyphenator.config({
		displaytogglebox : false,
		minwordlength : 4
	});
	Hyphenator.run();
	
	$(".reflectImage").reflect({ height: 20, opacity: .6 });
	
	// SUCHE
	
	/*$( "#searchfield" ).autocomplete({
		source: "/scripts/autocomplete.php",
		minLength: 2,
		focus: function( event, ui ) {
			$( "#searchfield" ).val( ui.item.value );
			return false;
		},
		select: function( event, ui ) {
			document.location.href=ui.item.slink;
		}
	}).data( "autocomplete" )._renderItem = function( ul, item ) {
			return $( "<li></li>" )
				.data( "item.autocomplete", item )
				.append( "<a href='"+ item.slink +"'><strong>" + item.label + "</strong><br>" + item.desc + "</a>" )
				.appendTo( ul );
		};*/
	
});

function init_canvas() {
	$(".slider.navigation").children(".background").children("span").liquidCanvas("[gradientW{from:#98a3a6; to:#c5d2d4;} border{color:#85898b; width:1}] => roundedRect{radius:5}");
	
	$(".slider.navigation").children(".arrow.left").children("span").liquidCanvas("[fill{color:#fff} border{color:#8c9698; width:1}] => arrowL");
	$(".slider.navigation").children(".arrow.right").children("span").liquidCanvas("[fill{color:#fff} border{color:#8c9698; width:1}] => arrowR");
	
	$(".slides span").each(function(index) {
		if(index==0) {
			$(this).children("div").liquidCanvas("[gradientW{from:#eb8e30; to:#fecc00;}] => slider");
		} else {
			$(this).children("div").liquidCanvas("[fill{color:#fee5cb}] => slider");
		}
		
		$(this).css({ left: index*53 });
	});
	
	$("span.subnavigation ul.subnavigation").each(function() {
		$(this).liquidCanvas("[border{color:#f08d28; width:1}] => subNav{color: rgba(255, 255, 255, 0.8)}"); 
	});
	
	$("span.subsubnavigation ul.subsubnavigation").each(function() {
		$(this).liquidCanvas("[border{color:#f08d28; width:1}] => subsubNav{color: rgba(255, 255, 255, 0.8)}"); 
	});
	
	var spanhover = false;
	$("li span.subnavigation").each(function() {
		$(this).css({ display: "none" });
		
		$(this).parent().hover(
			function() {
				$(this).children("span").css({ display: "block" });
				$(this).children("span").hover(
					function() {
						spanhover = true;
					},
					function() {
						spanhover = false;
					}
				);
			},
			function() {
				if(!spanhover) {
					$(this).children("span").css({ display: "none" });
				}
			}
		);
		
	});
	
	var spansubhover = false;
	$("li span.subsubnavigation").each(function() {
		$(this).css({ display: "none" });
		
		$(this).parent().hover(
			function() {
				$(this).children("span").css({ display: "block" });
				$(this).children("span").hover(
					function() {
						spansubhover = true;
					},
					function() {
						spansubhover = false;
					}
				);
			},
			function() {
				if(!spansubhover) {
					$(this).children("span").css({ display: "none" });
				}
			}
		);
		
	});
	
}

function init_searchfield() {
		$(".searchfield").focus(function() {
			$(this).attr("value", "");								 
		});
}

function init_ie() {
	
	$(".slider.holder .slide").each(function(index) {
	
		var vholder = $("<span/>").css({ width: 900, height: 263 });
		var vgroup = $("<v:group/>").css({ width: 900, height: 263 });
		var vshape = $("<v:shape/>").css({ width: 900, height: 263 }).attr("coordorigin", "0 0").attr("coordsize", "900 263").attr("strokecolor", "#009446").attr("strokeweight", "0pt");
		var vpath  = $("<v:path/>").attr("v", "m 70,0 l 900,0, 830,263, 0,263 x e");
		var vfill  = $("<v:fill/>").attr("type", "frame").attr("src", $(this).children("span").children("img").attr("src"));
		
		$(vshape).append(vpath);
		$(vshape).append(vfill);
		$(vgroup).append(vshape);
		$(vholder).append(vshape);
		
		$(this).children("span").remove();
		$(this).append(vholder);

		/*if(index==$(".slider.holder").children(".slide").length-1 && $(".slider.holder").children(".slide").length>1) {
			$(this).css({ left: -834 });
		} else {
			$(this).css({ left: index*834 });
		}*/
		$(this).css({ left: index*834 });
		
		slides.push($(this));
		
	});
	
	/*var el = null;
	var el = $.extend(el, $(slides[0]));
	$(el).appendTo(".slider.holder").css({ left: -835 });
	*/
	$(".slider.holder").css({ left: -2 });
	
	init_slider_nav();
	
}

function init_browser() {
	
	$(".slider.holder .slide").each(function(index) {
		if($(this).hasClass("ac")) { acs = index; }										 
	});
	
	$(".slider.holder .slide").each(function(index) {
		$(this).children("span").liquidCanvas("fill => imageslice{url:"+$(this).children("span").children("img").attr("src")+"}");
		$(this).children("span").children("img").remove();
		/*
		if(index==$(".slider.holder").children(".slide").length-1 && $(".slider.holder").children(".slide").length>2) {
			$(this).css({ left: -835 });
		} else {
			$(this).css({ left: index*835 });
		}
		*/
		$(this).css({ left: index*835 - (acs*835) });
		if(index!=acs) {
			$(this).css({ opacity: .5 });	
		}
		slides.push($(this));
		
		
		
	});	
	
	/*var el = null;
	var el = $.extend(el, $(slides[slides.length-1]));
	$(el).appendTo(".slider.holder").css({ left: -835 });*/

	check_loader = window.setInterval(function() { 
		if(count_loads > $(".slider.holder").children("span").length) {
			init_loaded();
		}
	}, 10);
}



function init_loaded() {
	window.clearInterval(check_loader);
	
	/*$("#container.slider").touchwipe({
     wipeLeft: function() { wipe_left() },
     wipeRight: function() { wipe_right() },
     wipeUp: function() {  },
     wipeDown: function() {  },
     min_move_x: 20,
     min_move_y: 20,
     preventDefaultEvents: true
	});*/
	
	init_slider_nav();
	
}

function init_slider_nav() {
	//$(".slider.navigation").children(".arrow.left").click(function() { wipe_left(); });
	//$(".slider.navigation").children(".arrow.right").click(function() { wipe_right(); });
	$(".slides").children("span").children("div").click(function() { document.location.href=$(this).attr("rel"); });
}

var count_steps=0;
function slider_step() {
	
}

function wipe_left() {
	ac_index++;
	
	$(".slider.holder").animate({ left: -ac_index*835 }, {duration: 2000, easing: "easeOutQuint", step: function( currentLeft ){ slider_step(); } });
	
	$(".slider.holder .slide").each(function(index) {
		if(index==ac_index) {
			$(this).animate({ opacity: 1 }, {duration: 2000, easing: "easeOutQuint" });
		} else {
			$(this).animate({ opacity: .5 }, {duration: 2000, easing: "easeOutQuint" });	
		}
	});
	
	
}

function wipe_right() {
	ac_index--;
	$(".slider.holder").animate({ left: -ac_index*835 }, {duration: 2000, easing: "easeOutQuint", step: function( currentLeft ){ slider_step(); } });
	
	$(".slider.holder .slide").each(function(index) {
		if(index==ac_index) {
			$(this).animate({ opacity: 1 }, {duration: 2000, easing: "easeOutQuint" });
		} else {
			$(this).animate({ opacity: .5 }, {duration: 2000, easing: "easeOutQuint" });	
		}
	});
	
	
}


function EMail(s)
	{
		var a = false;
		var res = false;
		if(typeof(RegExp) == 'function')
		{
			var b = new RegExp('abc');
			if(b.test('abc') == true){a = true;}
		}
	
		if(a == true)
		{
			reg = new RegExp('^([a-zA-Z0-9\\-\\.\\_]+)'+
			'(\\@)([a-zA-Z0-9\\-\\.]+)'+
			'(\\.)([a-zA-Z]{2,4})$');
			res = (reg.test(s));
		}
		else
		{
		res = (s.search('@') >= 1 &&
		s.lastIndexOf('.') > s.search('@') &&
		s.lastIndexOf('.') >= s.length-5)
		}
		return(res);
	} 

