$(document).ready(function(){





  $("#mainnavi a").each(function(i){
    if (($(this).attr("href")) == Url.decode(document.URL)) $(this).css("background",'#aaa');
    if (Url.decode(document.URL)=="http://www.bavaria-bowling.com/gallerie" && ($(this).attr("href")) == "http://www.bavaria-bowling.com/bavaria-bowling, location") $(this).css("background",'#aaa');
  });



//return;


/*
  $('a[href*=#]').bind("click", function(event) {
    event.preventDefault();
    var ziel = $(this).attr("href");
    $('html,body').animate({
      scrollTop: $(ziel).offset().top
    }, 2000 , function (){location.hash = ziel;});
  });
*/





  if($.cookie('colorindex')) {
    setDiffColors(mcolors[$.cookie('colorindex')]);
  }
  
    if (!$.browser.msie)
    {
     // $('#bevent img').css('background','#000000');
     // $('#bevent img').dropShadow({opacity: 0.3, left: 3, top: 3+$('#middlecont').scrollTop(), blur: 3,color:'#000'}); 
      //$('#middlecont').jScrollPane();
    }

  $("#middlecont a").each(function(i){
  
    if($(this).find('img').length!=0 && document.URL !='http://www.bavaria-bowling.com/partner'){
      $(this).fancybox({
        'click' : 'click',
        'titleShow'     : true
        });
    }
  });



    for (var n=0;n<8;n++)
    $(".farbwaehler").append('<div title="Lieblings-Farbe setzen." class="fchoose"></div>');
    $(".farbwaehler div").mouseup(function(){
      setDiffColors(mcolors[$(".farbwaehler div").index(this)]);
      $.cookie('colorindex', $(".farbwaehler div").index(this),{ path: '/', expires: 10 });
    });
 
    
    setSite();

    //login-field
    var tmr;
    $("#loginfield").hover(
      function () {
        clearTimeout(tmr);
        $("#loginfield").animate(
          {"height": "160px", "width": "140px"},
        "fast" );
      }, 
      function () {
        tmr=setTimeout("$('#loginfield').animate({'height': '20px', 'width': '50px'},'fast');",2000);
      }
    );
    
    $("#logo").attr('title','Startseite');
    $("#logo").click(function() {
      window.location = url_server; 
    });

    $(".seitenzahlen a").mouseup(function() {
        if( $('.nvisi'+(parseInt ($(this).html())-1)).hasClass('nvisi') !== true ) return;
        setVisible($(this).html());
    });
    
    
    
    
    
  $('.layout-login-0').corner();
  //$('#middlecont').corner();

//    $('#layer2_top_left div div div').corner("round 5px");
 

  timer_keepsession = setInterval(function () {
    $.ajax({
       type: "POST",
       url: url_server+"_lib/php/keepsession/keepsession.php",
       error: function(msg){
       },
       success: function(msg){
       }
     });
  },60000);



  $(".wk_button").hover(
    function () {
      $(this).removeClass("bg_common_text_color_2");
      $(this).addClass("little_basket_hover");
    }, 
    function () {
      $(this).removeClass("little_basket_hover");
      $(this).addClass("bg_common_text_color_2");
    }
  );



    $("#send_kontakt").click(function() {
      elmArray =  new Array();
      elmArray = returnElmValArray('wfield');
        var gdata = {
          url:          url_server+"fajaxload",
          cls:          'common',
          elmarray:      elmArray,
          validate:      'checkin',
          func:         'kontaktformular'
        };       
        flow_actions(gdata);
    });

imagePreview();
 // return false;

});//ende doc ready




function returnElmValArray(objectclass){
  elmArray =  new Array();
  elmArray={'ahelp': 'ahelp'};
  $("."+objectclass).each(function(i){
    var sval=$(this).val();
    if ($(this).is('input:checkbox')) $(this).is(':checked') ? sval='1' : sval='0';
    if($(this).is('[type=textarea]')) sval = $(this).val();
    sval = Url.encode(sval);
    if ($(this).attr("name")) elmArray[$(this).attr("name")]=sval;
  });
  return   elmArray ; 
}


var Url = {
 
  // public method for url encoding
  encode : function (string) {
    return escape(this._utf8_encode(string));
  },
 
  // public method for url decoding
  decode : function (string) {
    return this._utf8_decode(unescape(string));
  },
 
  // private method for UTF-8 encoding
  _utf8_encode : function (string) {
    string = string.replace(/\r\n/g,"\n");
    var utftext = "";
 
    for (var n = 0; n < string.length; n++) {
 
      var c = string.charCodeAt(n);
 
      if (c < 128) {
        utftext += String.fromCharCode(c);
      }
      else if((c > 127) && (c < 2048)) {
        utftext += String.fromCharCode((c >> 6) | 192);
        utftext += String.fromCharCode((c & 63) | 128);
      }
      else {
        utftext += String.fromCharCode((c >> 12) | 224);
        utftext += String.fromCharCode(((c >> 6) & 63) | 128);
        utftext += String.fromCharCode((c & 63) | 128);
      }
 
    }
 
    return utftext;
  },
 
  // private method for UTF-8 decoding
  _utf8_decode : function (utftext) {
    var string = "";
    var i = 0;
    var c = c1 = c2 = 0;
 
    while ( i < utftext.length ) {
 
      c = utftext.charCodeAt(i);
 
      if (c < 128) {
        string += String.fromCharCode(c);
        i++;
      }
      else if((c > 191) && (c < 224)) {
        c2 = utftext.charCodeAt(i+1);
        string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
        i += 2;
      }
      else {
        c2 = utftext.charCodeAt(i+1);
        c3 = utftext.charCodeAt(i+2);
        string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
        i += 3;
      }
 
    }
 
    return string;
  }
 
}


  function gr_set_check2 (name) {
    if (document.getElementsByName("gr_ch"+name)[0].checked==true) document.getElementsByName(name)[0].value="1";
    if (document.getElementsByName("gr_ch"+name)[0].checked==false) document.getElementsByName(name)[0].value="0";
  }

  function setVisible(mval){
      $('.seitenzahlen').css('text-decoration','none');
      $('#seitenzahlen').find('a:eq('+(mval-1)+')').parent().css('text-decoration','underline');
      var mkl=$('.nvisi'+(parseInt (mval)-1));
      $('.tcontent').animate({
        opacity: 0.0
      }, 100, function() {
        $('.tcontent').addClass('nvisi');
        mkl.removeClass('nvisi');
        $('.tcontent').animate({
          opacity: 1
        }, 100, function() {
        });
      });
  }

function setSite(){
    var surl = document.URL;
    var ssearch = surl.search(/#seite_/);
    if (ssearch != -1){
      surl_s1 = surl.split('#');
      surl_s2 = surl_s1[1].split('_');
      setVisible(surl_s2[1]);
    } else {
      setVisible(1);
    } 
}

function IncludeJavaScript(jsFile)
{
  document.write('<script type="text/javascript" src="'
    + jsFile + '"></scr' + 'ipt>'); 
}


function flow_actions(gudata){
          gdata = JSON.stringify(gudata);
          $el=$(document);
          $.ajax({ 
              type: "post",
              url: url_server+"fajaxload",
              data: {gdata:  gdata},
              cache: false,
              error: function(request, settings,ob){
                $el.find('.ladepic').css("display","none");
              },
              beforeSend : function(){
                $el.find('.ladepic').css("display","block");
              },
              complete: function(){
                $el.find('.ladepic').css("display","none");
              },
              success: function(html) {
                $('#h_cont').html(html);
              }
            });
}


//user-spec
  var maindelay=10000;
  var delay0=maindelay*10;var delay1=maindelay;
  var tHandle=0;
  var tHandle0=window.setInterval(gr_func0, delay0);
  
  function setDiffColors (mcolor){
    $('body').css('background-color',mcolor);
    $('#layer').css('background-color',mcolor);
  }
  var mcolors=new Array("#1cbdd7","#ffd37f","#cce5b2","#d83800","#eb3af2","#b1b1b1","#422e5d","#009383"); 
    $(this).mousemove(function(){
      window.clearTimeout(tHandle);
      if (tHandle0==0) tHandle0=window.setInterval(gr_func0, delay0);
      if($.cookie('colorindex')) setDiffColors(mcolors[$.cookie('colorindex')]); else setDiffColors(mcolors[0]);
    });
  function gr_func0() {
    window.clearTimeout(tHandle0);tHandle0=0;
    tHandle=window.setInterval(gr_func, delay1);
  }
  function gr_func() {
    randColor();
  }
  function randColor() { 
    var randColor = ""; 
    for (var zC = 1; zC < 7; zC++){
      var Farbe = "0123456789ABCDEF";
      var RND = Math.round(Math.random() * 15);
      randColor += Farbe.substr(RND, 1);
      }
    setDiffColors("#" + randColor);
  }



function selectItem(li) {
  findValue(li);
}
function findValue(li) {
  if( li == null ) return;
  if( !!li.extra ) var sValue = li.extra[0];
  else var sValue = li.selectValue;
}

this.imagePreview = function(){	
	/* CONFIG */
		xOffset = 250;
		//xOffset = height/2;
		yOffset = 30;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.preview").hover(function(e){
		//grazer
		var ni, newImg = document.createElement('IMG');
		newImg.src=this.href;
//		var xOffset = newImg.naturalHeight/2;
		var xOffset = newImg.height/2;
		//
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='preview'><img src='"+ this.href +"' alt='Image preview' />"+ c +"</p>");								 
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#preview").remove();
    });	
	$("a.preview").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
	$("a.preview").mousedown(function(e){
		return false;
	});			

    $("a.preview").click(function() {
      return false; 
    });
	
	
	
};



