$(document).ready( function(){
  
  if ($('#galeriebilder').length > 0){
    /* This script and many more are available free online at
    The JavaScript Source!! http://javascript.internet.com
    Created by: Abraham Joffe :: http://www.abrahamjoffe.com.au/ */
    document.onmousedown = function(){
      var e= arguments[0] || event || evt;
      var x= zxcWWHS()[2] + e.clientX;
      //var y= zxcWWHS()[3] + e.clientY;
      //console.log(e);
      document.onmousemove=function(){
        var e=arguments[0]||event;
        window.scroll(x-e.clientX,y-e.clientY);
        return false;
      }
      document.onmouseup=function(){
        document.onmousemove=null;
      }
      return false;
    }
  }
  
  /*
  $(function() {
    $("div#makeMeScrollable").smoothDivScroll({scrollingSpeed: 12, mouseDownSpeedBooster: 3, autoScroll: "onstart", autoScrollDirection: "endlessloop", autoScrollSpeed: 2, visibleHotSpots: "onstart", hotSpotsVisibleTime: 9, startAtElementId: "startAtMe"});
  });
  */
  $("div#smallScroller").smoothDivScroll({mouseDownSpeedBooster: 2, scrollingSpeed: 7, visibleHotSpots: "onstart", hotSpotsVisibleTime: 9});
  
  //$("#center").draggable({ axis: 'x', cursor: 'move', scroll: false });
  
  /* MEN† */
	//$("ul.subnav").parent().append("<span>test</span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)

	$("ul.mainmenu li a").hover(function() { //When trigger is clicked...

		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click

		$(this).parent().hover(function() {
		}, function(){
			$(this).parent().find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
		});

		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() {
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
	});
	
  setPositions();
  
  if ($('#slideshow').length > 0){
    // rotating fading bbc logos
    $('#slideshow').show();
    $('#slideshow').innerfade({ speed: 1500, timeout: 7000, type: 'sequence', containerheight: '424px' });
  }
  
  if ($('.lightbox').length > 0){
    $('.lightbox').lightBox();
  }
});


$(window).bind("resize", function(){
  setPositions();
});

	
function setPositions() {
  var browserwidth = $(window).width();
  var browserheight = $(window).height();
  var vertical_center = browserheight / 2;
  var logo_y_pos = vertical_center - 292;
  var thumbs_y_pos = vertical_center + 241;
  var kontakt_x_pos = browserwidth - 193;
  var kontakt_y_pos = browserheight - 180;
  
  if (($.browser.msie && $.browser.version == '6.0') || $.browser.safari) {
    // dann scrollt eben alles
  } else {
    $('#header').fixedBox({x: 37, y:logo_y_pos});
    $('#smallScroller').fixedBox({x: 37, y:thumbs_y_pos});
    //$('#scrollingHotSpotLeft').fixedBox({x: 37, y:thumbs_y_pos});
    $('#smallScroller').width(browserwidth - 225);
  }
  
  $('#kontakt-ecke').fixedBox({x: kontakt_x_pos, y:kontakt_y_pos});
  
  //console.log("test");
};










function zxcWWHS(){
 if (window.innerHeight) 
   return [window.innerWidth-10,window.innerHeight-10,window.pageXOffset,window.pageYOffset];
 else if (document.documentElement.clientHeight) return [document.documentElement.clientWidth-10,document.documentElement.clientHeight-10,document.documentElement.scrollLeft,document.documentElement.scrollTop];
   return [document.body.clientWidth,document.body.clientHeight,document.body.scrollLeft,document.body.scrollTop];
}