//alert (location.href);
if (location.href.lastIndexOf("/") == location.href.length-1)
    location.href = location.href + "index.html#Home";
if (location.href.lastIndexOf(".html") == location.href.length-5)
    location.href = location.href + "#Home";
vars = new Array();
jQuery.each(jQuery.browser, function(i, val) {
    vars[i]=val;
});
//$("<div>" + vars + "</div>").appendTo(document.body);
//alert(vars["version"]);
//if (vars["msie"] == true && (vars["version"].indexOf("6") == 0 || vars["version"].indexOf("5") == 0)) {
//    location.href = "ie6_fehler.html";
//}
if (jQuery.support.boxModel == false)
    location.href = "ie6_fehler.html";


var slideleft=1;

function scrollWindow() {
    conveyor = $(".content-conveyor", $("#sliderContent"));
    itemb = $(".item");
    conveyor_max = (itemb.length * parseInt(itemb.css("width"))) - parseInt($(".viewer", $("#sliderContent")).css("width"));
    var slideValue;
    slideValue = $("#slider").slider("value");
    //alert(slideValue);
    //alert(conveyor_max);
    if(slideValue < conveyor_max-3 && slideleft==1)
    {
        $("#slider").slider("value", slideValue + 3);
	conveyor.css("left", "-" + (slideValue + 3) + "px");
    } else if(slideValue > 3 && slideleft==0) {
        $("#slider").slider("value", slideValue - 3);
	//conveyor.animate({"left": "-" + (slideValue-10) + "px"}, 50);
	conveyor.css("left", "-" + (slideValue - 3) + "px");
    } else if(slideleft == 1) {
	slideleft=0;
	//alert("ich slide von nun an nach rechts");
    } else {
	slideleft=1;
	//alert("ich slide von nun an nach links");
    }
    slidetimer = setTimeout(scrollWindow, 150);
}

//google.load("jquery", "1.3.2");
$(document).ready(function(){
    $("#menubar").load("markrans-card-backend.php?action=get_navi_final", {}, function(responseText, textStatus, XMLHttpRequest){
	$('.ajaxify_navi').ajaxify({
	    //animateOut:{opacity:'0.2'},
	    //animateOutSpeed:500,
	    //animateIn:{opacity:'1'},
	    //animateInSpeed:500,
	    loading_target:'#content-a',
	    loading_img:'images/loading.gif',
	    target:'#content-a',
	    loadHash:'attr:rel',
	    onComplete:function(options){
		$(".typeface-js>h1").prepend("<span></span>");
		Cufon.replace('.typeface-js');
		$("#sponsoren-div").load("markrans-card-backend.php?action=get_sponsoren",{},function(responseText, textStatus, XMLHttpRequest){
		      $("a[rel='sponsoren']").colorbox({iframe:true, width:650, height:550});
		  });
		$("#kontakt-form").submit(function() {
		  if ($("#form-name").val() != "" && $("#form-mail").val() != "" && $("#form-text").val() != "") {
		    $("#form-response").text("Nachricht wurde versendet.").show();
		    $("#kontakt-form").hide();
		    $.post("markrans-card-backend.php", "action=send_mail&mail_name="+encodeURIComponent($("#form-name").val())+"&mail_mail="+encodeURI($("#form-mail").val())+"&mail_text="+encodeURIComponent($("#form-text").val()), function(data){
			$("#form-response").text(data).show();
		    }, "text");
		    return true;
		  }
		  $("#form-response").text("Bitte Eingaben überprüfen").show();
		  return false;
		  
		});
		$("#content-a").attr("style","");
		//alert($("#content-a").css("font-family"));

	    }
	    });
	$(".ajaxify_navi").click(function(){
	    this.blur();
	});
	$(".navi").click(function(){
	    mo_event=this.onmouseover;
	    Ausdruck = /"(.+)"/;
	    Ausdruck.exec(mo_event);
	    mo_bild=RegExp.$1;
	    this.onmouseout="function onmouseout(event) {this.src = \""+mo_bild+"\";}";
	    if (document.getElementById("navi_active")) {
		navi_active=document.getElementById("navi_active");
		mo_event=navi_active.onmouseover;
		Ausdruck = /"(.+)-active.png"/;
		Ausdruck.exec(mo_event);
		mo_bild=RegExp.$1;
		navi_active.onmouseout="function onmouseout(event) {this.src = \""+mo_bild+".png\";}";
		navi_active.src=mo_bild + ".png";
		navi_active.id="";
	    }
	    this.id = "navi_active";
	});

    });
    $("#slider").load("markrans-card-backend.php?action=get_labels");
    $("#viewer").load("markrans-card-backend.php?action=get_sponsoren_slider",{},function(responseText, textStatus, XMLHttpRequest){
	var conveyor = $(".content-conveyor", $("#sliderContent")),
	item = $(".item", $("#sliderContent"));
	conveyor_max = (item.length * parseInt(item.css("width"))) - parseInt($(".viewer", $("#sliderContent")).css("width"));
	//set length of conveyor
	conveyor.css("width", item.length * parseInt(item.css("width")));
	counter=0;
	//config
	var sliderOpts = {
	    animate: true,
	    max: conveyor_max,
	    slide: function(e, ui) { 
		    if (counter < 10) counter++;
		    else {
			//conveyor.css("left", "-" + ui.value + "px");
			conveyor.animate({"left": "-" + ui.value + "px"}, 100);
			counter = 0;
		    }
		    //if (jQuery.support.noCloneEvent != false)
			clearTimeout(slidetimer);
		  },
	    stop: function(e, ui) { 
		    conveyor.animate({"left": "-" + ui.value + "px"}, 500);
		    //if (jQuery.support.noCloneEvent != false)
			clearTimeout(slidetimer);
		  }
		  
	};
	$("#slider").slider(sliderOpts);
	$("a[rel='sponsoren']").colorbox({iframe:true, width:650, height:550});
	$("a[rel='sponsoren-slider']").colorbox({iframe:true, width:650, height:550});
	$("#iconright").click(function () { 
	    //sliderpos_new = 500;
	    //alert($("#slider").slider('value'));
	    sliderpos = $("#slider").slider('value');
	    //alert(item.css("width"));
	    sliderpos = sliderpos + parseInt($(".viewer").css("width"))/3;
	    if (sliderpos > conveyor_max)
		sliderpos = conveyor_max;
	    $("#slider").slider('value',sliderpos); 
	    conveyor.animate({"left": "-" + sliderpos + "px"}, 300);
	});
	$("#iconleft").click(function () { 
	    //sliderpos_new = 500;
	    //alert($("#slider").slider('value'));
	    sliderpos = $("#slider").slider('value');
	    //alert(item.css("width"));
	    sliderpos = sliderpos - parseInt($(".viewer").css("width"))/3;
	    if (sliderpos < 0)
		sliderpos = 0;
	    $("#slider").slider('value',sliderpos); 
	    conveyor.animate({"left": "-" + sliderpos + "px"}, 300);
	});
	$(".sponsorimg").mouseover(function(){
	    this.src=this.id + "-small-bw.png"
	}).mouseout(function(){
	    this.src=this.id + "-small.png"
	});
    });
    $('#dialog_link, ul.icons li').hover(
      function() { $(this).addClass('ui-state-hover'); },
      function() { $(this).removeClass('ui-state-hover'); }
    );
    //alert(jQuery.support.noCloneEvent);
    //if (jQuery.support.noCloneEvent != false) {
    //noCloneEvent
	slidetimer = setTimeout(scrollWindow, 3000);
	$("#footer > *").click(function(){
	    clearTimeout(slidetimer);
	});
    //}
});


