var _trigger = false;
var disableMenuHover = 0;
var buttonRel = '';
var buttonRelPressed = 1;

var globalhash = location.hash;
var ajaxclickinaction = 0;

function ajaxClick(el, href, contentTag, callback){
  if (el) {
    var skip = jQuery(el).attr('skipclick');
    var regexp = /^javascript:/;
    var go = (skip != 1) && (!regexp.test(el.href)) && !jQuery(el).hasClass('external');
  } else {
    var go = true;
  }
	if (go) {
    if (el) {
      href = el.href;
    }
          
    //Load the AJAX page (this is a whole other topic)
    jQuery(contentTag).load( href + ' ' + contentTag, callback);

    //Update the address bar to make it look like you were redirected
    var locationhref = location.href;
    var idx = locationhref.lastIndexOf('#');
    if (idx > 0) { locationhref = locationhref.substr(0, idx); }
    var hash = href.replace(locationhref, '');
    if (_trigger == true) {
      jQuery('.hentry').stop().animate({"top": -(1500)}, 1000);
    }
    ajaxclickinaction = 1;
    location.hash = '#' + hash;

    //Unfocus the link to make it look like you were redirected
    if (el) {
      //el.blur();
    }
	}
  
}

function turnSiteToAjaxMode(contentTag, callback) {

	//var header = document.getElementById('header');
	var headerLinks = document.getElementsByTagName('a');
  
	for (var i = 0, l = headerLinks.length; i < l; i++) {
    if (!jQuery(headerLinks[i]).hasClass('external')) {
      headerLinks[i].onclick = function() {
        ajaxClick(this, '', contentTag, callback);
        //Prevent the natural HTTP redirect
        return false;
      }
    }
	}

}

jQuery(function(){

    var jQueryel, leftPos, newWidth,
        jQuerymainNav = jQuery("ul#menu-top-menu");
        jQuerymainNavLi = jQuery("ul#menu-top-menu li");
		jQuerymainNav.css("opacity", 0);
    
    var jQuerymagicLine = jQuery("#magic-line");
	var bodycurclass = jQuery("input#page_class").attr("class");
	var pageimgMain = jQuery(".pageimage");
	var pageimg = jQuery(".pageimage div");
	//var hentry = jQuery(".hentry");
	var curhref;	
	var menustatus = false;	
	
	//CHECK ON SMALL SCREEN
	var screenw = screen.width;
	var screenh = screen.height;
	if(screenw == 1024 && screenh == 768){
		jQuerymagicLine.css({ "font-size": "30px", "padding-left": "16px", "padding-right": "16px" });
		jQuerymainNavLi.find("a").css({ "font-size": "30px", "padding-left": "16px", "padding-right": "16px" });
		pageimgMain.attr("id", "screen1024");
	}
	
	if (screenw >= 1600) {	  
		jQuery("#page").css({ height: parseInt(jQuery(document).height())-23 });
		jQuery(".hentry").css({ height: parseInt(jQuery(document).height())-50-190 });
		
	}
	
	//jQuery(".pageimage").attr("id", "screen"+screenw);
	
	if (screenw > 1024 && screenw <= 1152) {
		pageimgMain.attr("id", "screen1152");
	}
	
	if (screenw >= 1200 && screenw <= 1280) {
		pageimgMain.attr("id", "screen1280");
	}
	
	if (screenw >= 1300 && screenw <= 1366) {
		pageimgMain.attr("id", "screen1366");
	}
	
	if (screenw >= 1400 && screenw <= 1440) {
		pageimgMain.attr("id", "screen1440");
	}
	
	if (screenw > 1440 && screenw <= 1600) {
		pageimgMain.attr("id", "screen1600");
	}
	
	if (screenw > 1600 && screenw <= 1680) {
		pageimgMain.attr("id", "screen1680");
	}
	
	if (screenw > 1680 && screenw <= 1920) {
		pageimgMain.attr("id", "screen1920");
	}
	
	
	//CHECK WELCOME TEXT COOKIE
	if(jQuery.cookie('welcome_text')) { jQuery(".homepresent").remove(); }

	pageimg.css({ opacity: 0 })
	jQuerymainNavLi.removeAttr("id").removeAttr("class");
	
	jQuerymainNavLi.each(function(){
		curlinkhref = jQuery(this).find("a").attr("href");
		curlinktext = jQuery(this).find("a").text();
		if (curlinktext != bodycurclass) {
			hrf = curlinkhref.substring(curlinkhref.lastIndexOf('/') + 1, curlinkhref.length);
			if(hrf==""){ jQuery(this).addClass("home").find("a").addClass("home"); }else{ jQuery(this).addClass(hrf).find("a").addClass(hrf); }
		}else{
			jQuery(this).addClass(bodycurclass).find("a").addClass(bodycurclass);
		}
	})
	
	pageimgMain.find("div."+bodycurclass).attr("id", "active");
	jQuerymainNavLi.find("a."+bodycurclass).attr("id", "current_page_item").addClass("active");
	pageimgMain.find("div#active").css({ opacity: 1 });
	jQuerymainNavLi.find("a").each(function(){
		jQuery(this).append("<span>"+jQuery(this).attr("title")+"</span>");
	})
	jQuerymagicLine.append("<span>" + jQuery(jQuerymainNavLi).find("a."+bodycurclass+" span").text() + "</span>");
	
	jQuerymagicLine.addClass(bodycurclass+"_item");
	
	//jQuery("ul.subnav").hide();
	
	
	//COLORS
	jQuerymainNavLi.find("a.home").attr("rel", "home_item").attr("rev", "#0059C9");
	jQuerymainNavLi.find("a.overons").attr("rel", "overons_item").attr("rev", "#FED86F");
	jQuerymainNavLi.find("a.contact").attr("rel", "contact_item").attr("rev", "#CC2200");
	jQuerymainNavLi.find("a.nieuws").attr("rel", "nieuws_item").attr("rev", "#CC0060");
	jQuerymainNavLi.find("a.referenties").attr("rel", "referenties_item").attr("rev", "#00C0CC");
	jQuerymainNavLi.find("a.fotos").attr("rel", "fotos_item").attr("rev", "#CC5B00");
	
	
	//MENU POSITION
	var menuulw = 0;
	jQuerymainNavLi.each(function(){
		menuulw = menuulw + parseInt(jQuery(this).width());
    jQuery(this).attr('originalWidth', jQuery(this).width());
	})
	jQuery("#page").css({"min-width": parseInt(menuulw)+5});
	jQuery(".topnavigation").css({"min-width": parseInt(menuulw)-10});
	menuposition = (jQuery(document).width() - (menuulw))/2;
	if (!(jQuery(document).width() < menuulw)){
		jQuerymainNav.css({ left: menuposition });
	}
	
	//SHOM MENU
	jQuerymagicLine.click(function(){
		jQuery(this).animate({height: 111});
		if(jQuery("input#page_class").hasClass("fotos")){
			jQuery(".pageimage div.fotos").animate({ opacity: 1 });
			jQuery(".fotospage").hide();
		}
		menuload();
	})
	
	jQuery("a.back").click(function(){
		if(!menustatus){
			jQuerymagicLine.animate({height: 111});
		if(jQuery("input#page_class").hasClass("fotos")){
			jQuery(".pageimage div.fotos").animate({ opacity: 1 });
			jQuery(".fotospage").hide();
		}
			menuload();
		}
	})
	
	pageimgMain.click(function(){
		if (jQuery(".hentry").length != 0) {
			jQuery(".hentry").stop().animate({"top": -(1500)}, 1000, function(){
				
			});
			jQuery("ul.subnav li a.active").removeClass("active");
		} else
    if (jQuery("body").hasClass("fotos"))	{
      history.back(-1);
    }
	})

	
	function a(){
		jQuery(".hentry").stop().animate({"top": 27}, 800);
		documentReady();
		windowLoad();

		turnSiteToAjaxMode('#content', function() {
		  
		  a();

		  jQuery('.scroll-pane').jScrollPane();
		  if (jQuery("body").hasClass("fotos"))	{
        setTimeout(function(){
          var fotoshtml = jQuery("ul#menu-top-menu li a.fotos").html()
          jQuerymagicLine.text('');
          pageimage.css({ opacity: 0 }).removeAttr("id");
          pageimgMain.animate({ backgroundColor: "#000000" }, 1000);
          pageimgMain.find("div.fotos").attr("id", "active");
          jQuerymainNavLi.find("a#current_page_item").removeAttr("id");
          jQuerymainNavLi.find("a.fotos").attr("id", "current_page_item");
          jQuerymagicLine
            .attr("class", "fotos_item")
            .css({width: jQuerymainNavLi.find("a.fotos").css("width")})
            .html(fotoshtml).fadeIn("slow");
          jQuery(".topnavigation").css({ borderColor: jQuerymainNavLi.find("a.fotos").attr("rev") })
          }, 100);
		  }
		});
  	menustatus = false;

		disableMenuHover = 0;
	}
	

	a();

	
setInterval(function()
{
    if (location.hash != globalhash)
    { 
        if (ajaxclickinaction == 0) {
          // back pressed
          var regexp = /#http/;
          if (regexp.test(location.href)) {
            var idx = location.href.indexOf('#');
            var href = location.href.substr(idx+1);
          } else {
            var href = location.href.replace('#', '');
          }
          ajaxClick(null, href, '#content', function(){
			a();
			
			jQuery('.scroll-pane').jScrollPane();
			
			if(jQuery(bodycurclass != jQuery("ul#menu-top-menu li a#current_page_item").attr("class")))	{
			  var curpage = jQuery("ul#menu-top-menu li a."+jQuery("input#page_class").attr("class"));
			  jQuerymagicLine
				.html(curpage.html())
				.attr("class", curpage.attr("rel"))
				.css({ width: "auto" });
			  //jQuery(".topnavigation").css({ borderColor: hoverbrd})
			  jQuery(".topnavigation").css({ borderColor: jQuery("ul#menu-top-menu li a."+jQuery("input#page_class").attr("class")).attr("rev") });
			  jQuerymainNavLi.find("a").removeAttr("id");
			  curpage.attr("id", "current_page_item");
			  pageimg.removeAttr("id").css({opacity: 0});
			  if(jQuery("input#page_class").attr("class") != "fotos") {
				jQuery(".pageimage div."+jQuery("input#page_class").attr("class")).attr("id", "active").animate({opacity: 1});
			  }else{
				pageimgMain.animate({ backgroundColor: "#000000" });
				jQuery(".pageimage div.fotos").attr("id", "active");
			  }
			  magiclineW = parseInt(jQuery("#magic-line").width()) + parseInt(jQuery("#magic-line").css("paddingLeft")) + parseInt(jQuery("#magic-line").css("paddingRight"));
			  jQuery(".hentry").css({ width: parseInt(jQuery("h1#logo").width()) + magiclineW });
			}
		  });
        }
        globalhash = location.hash;
        ajaxclickinaction = 0;
    }
}, 100);
	
	jQuerymainNavLi.find("a").attr('skipclick', 1);
	 
		jQuerymainNavLi.find("a").click(function(){

		if(!(jQuery(this).hasClass("home"))){
			disableMenuHover = 1;
			jQuery("ul#menu-top-menu li.home a").removeClass("external");	
			
		}else{
			setTimeout(function(){
				jQuery("ul.subnav").show();
			}, 2300);
		}

		 if(!(jQuery(this).hasClass("fotos")) /*&& !(jQuery(this).hasClass("home"))*/) {
			 var curlink = this;
			 curtext = jQuery(this).html();
			 curhref = jQuery(this).attr("href");
			 jQuery(this).attr("href", "javascript: void(0);");
			 jQuerymagicLine.html(curtext);
			 
			jQuerymainNavLi.find("a").removeAttr("id").removeClass("active");
			jQuery(this).attr("id", "current_page_item").addClass("active"); 
			
			 jQuerymainNav.fadeOut(function(){
				 jQuerymagicLine.animate({height: 76}, function(){
					 jQuery(".nav-wrap").animate({width: 0}, function(){
						 jQuerymagicLine.animate({left: 506}, function(){
							 curlink.href = curhref;
							 jQuery(curlink).attr('skipclick', 0);
							 ajaxClick(curlink, '', '#content', function(){ a();  });
							 jQuery(curlink).attr('skipclick', 1);
						 })
					 });
				 })
			 });
			 
		 }else{
			 
			 var curlink = this;
			 curtext = jQuery(this).html();
			 curhref = jQuery(this).attr("href");
			 jQuery(this).attr("href", "javascript: void(0);");
			 jQuerymagicLine.html(curtext);
			 
			 jQuerymainNavLi.find("a").removeAttr("id").removeClass("active");
			jQuery(this).attr("id", "current_page_item").addClass("active"); 
			 
			 pageimgMain.css("backgroundColor", "#fff");
			 jQuery(".pageimage div.fotos").animate({ opacity: 0 }, "fast");
			 pageimgMain.animate({ backgroundColor: "#ffffff" }, 700, function(){
				 pageimgMain.animate({ backgroundColor: "#000000" }, 1500, function(){});
				 jQuerymainNav.fadeOut(function(){
					 jQuerymagicLine.animate({height: 76}, function(){
						 jQuery(".nav-wrap").animate({width: 0}, function(){
							 jQuerymagicLine.animate({left: 506}, function(){
								curlink.href = curhref;
								jQuery(curlink).attr('skipclick', 0);
								ajaxClick(curlink, '', '#content', function(){
									jQuery(".pageimage div."+bodycurclass).css({ opacity: 0 });
									a();
								});
								jQuery(curlink).attr('skipclick', 1);
							})
						 });
					 })
				 });	
			 });
			 
		 }
		 
		 return false;
		 
	 })	
	

	
	function menuload(){
		if(_trigger == true) { 
			jQuery(".hentry").stop().animate({"top": -(1500)}, 1000);
		}
		jQuery("ul.subnav").fadeOut(800);
		jQuery(".lang").slideUp();
		
		
		if(bodycurclass=="fotos")	{
			pageimgMain.fadeIn(800);
			jQuery(".fotospage").hide(100);
		}
		
		jQuery(".nav-wrap").animate({width: "100%"}, 2000, function(){
			jQuerymainNav.css({ top: -200, display: "block" })
				lpos = jQuery("a#current_page_item").position().left+menuposition;
				jQuerymagicLine.animate({ left: lpos }, 800, function(){
					jQuerymainNav.css("top", 27);
					jQuerymainNav.animate({opacity: 1}, function(){
						
						jQuerymagicLine.text('');
						
						var padleft = parseInt(jQuerymainNavLi.find("a").css("paddingLeft"))
						var padright = parseInt(jQuerymainNavLi.find("a").css("paddingRight"))
						
						jQuerymagicLine
							.width(jQuery("a#current_page_item").parent().width()-(padleft+padright))
							//.animate({left: jQuery("a#current_page_item").position().left+menuposition}, 800)
							//.data("origLeft", jQuerymagicLine.position().left)
							//.data("origWidth", jQuerymagicLine.width());
							
						
						
						menustatus = true;
						
					});
				})
		});
	}
	
	jQuerymainNavLi.hover(
      function() { if (disableMenuHover == 0) { hoveredItem(jQuery(this)); } }
    , function() { if (disableMenuHover == 0) { overedItem(); }  }
  );
	
	function hoveredItem(item){
		jQueryel = item.find("a");
		leftPos = 0;
	    leftPos = jQueryel.position().left+menuposition;
	    newWidth = jQueryel.parents().width() - parseInt(jQueryel.css("paddingLeft")) - parseInt(jQueryel.css("paddingRight"));
		hovercolor = jQueryel.attr("rel");
		hoverbrd = jQueryel.attr("rev");
		actcolor = jQuery("a#current_page_item").attr("rel");
		curclass = item.attr("class");	
		jQuerymagicLine.removeAttr("class");
		jQuerymagicLine.addClass(hovercolor);
	    
	    jQuerymagicLine.stop().animate({
	        left: leftPos,
	        width: newWidth
			//backgroundColor: hovercolor
	    });
	    
	    jQuery(".topnavigation").css({ borderColor: hoverbrd})
		
		if (!(jQueryel.hasClass("active") && jQueryel.hasId("current_page_item"))) {
			jQuery(".pageimage div").stop(true, true).animate({ opacity: 0 }, 500);
			jQuery(".pageimage div."+curclass).stop(true, true).animate({ opacity: 1 }, 220);
		}
		jQuerymainNav.find("li a").removeClass("active");
		jQueryel.addClass("active");
	}
	
	function overedItem(){
		jQueryel.removeClass("current_link");
	}
	
	documentReady();	
	
	
	//LANGUAGE
	jQuery(".lang p").click(function(){
		if(jQuery(".lang").hasClass("active")){
			jQuery(".lang").animate({ height: 18 }).removeClass("active");	
		}else{
			jQuery(".lang").animate({ height: 50 }).addClass("active");	
		}
	})
	
	
		
});


function documentReady(){
	
	var jQueryel, leftPos, newWidth,
        jQuerymainNav = jQuery("ul#menu-top-menu");
        jQuerymainNavLi = jQuery("ul#menu-top-menu li");
		jQuerymainNav.css("opacity", 0);
    
    var jQuerymagicLine = jQuery("#magic-line");
	var bodycurclass = jQuery("input#page_class").attr("class");
	var pageimgMain = jQuery(".pageimage");
	var pageimg = jQuery(".pageimage div");
	//var hentry = jQuery(".hentry");
	var curhref;	
	var menustatus = false;
	
	var screenw = screen.width;
	if (screenw >= 1600) {	  
		jQuery("#page").css({ height: parseInt(jQuery(document).height())-23 });
		jQuery(".hentry").css({ height: parseInt(jQuery(document).height())-50-190 });
	}
	
	jQuery("body").attr("class", bodycurclass);
	
	jQuery("iframe").css({display: "none"})
	
	
	
	jQuery("a.scrolltop").click(function(){
		jQuery(".hentry").stop().animate({"top": -(1500)}, 1000);
	})
	
	if(bodycurclass=="fotos")	{
		jQuery(".pageimage div."+bodycurclass).css({ opacity: 0 });
		jQuery(".fotospage").css({ opacity: 0 });
	}
	
	//IMAGE GALLERY
	imglink = [];
	count = 0;
	
	jQuery(".ngg-galleryoverview").css("display", "none");
	jQuery(".ngg-galleryoverview").each(function(){
		
		jQuery(this).find(".slideshowlink").remove();
		
		var counter = 0;
		
		images = Array();
		
		parentdiv = jQuery(this).parent("div")
		
		jQuery(this).find("a").each(function(){
			jQuery(this).attr("rel", "imgbox");
			images[counter] = jQuery(this).find("img").attr("src");
			imglink[counter] = jQuery(this).attr("href");
			counter++;
		})
		
		imgarray = 0;
		imgarray = jQuery(this).find("img").length;
		
		if(imgarray>12){
			parentdiv.append("<ul class='pagings'></ul>");
			parentdiv.append("<a href='javascript: void(0);' class='tleft'></a>")
			parentdiv.append("<a href='javascript: void(0);' class='tright'></a>")
			for(var i=0; i < imgarray; i++) {
				if(!(i%12)) 
					parentdiv.find("ul.pagings").append("<li><a href='javascript: void(0);'></a></li>");
			}
			parentdiv.find("ul.pagings li:first a").addClass("active");
		}
		var attrrel = 1;
		parentdiv.find("ul.pagings li a").each(function(){
			jQuery(this).attr("rel", attrrel);
			attrrel++;				
		})
		max = jQuery(images).length;
		var index = 0;
		
		jQuery(images).each(function(){
			if(!(index%12)){
				ul = jQuery('<ul class="imagegallery"></ul>');
				jQuery(ul).appendTo(jQuery(parentdiv));
				lngth = jQuery("ul.imagegallery").length;
			}
			
			var list = jQuery('<li id="portfolio_'+count+'" class="loading"><a href="'+imglink[index]+'" rel="imgbox"></a></li>');	
			ul.append(list);	
			var curr = jQuery("ul.imagegallery li#portfolio_"+count+" a");
			var curli = jQuery("ul.imagegallery li#portfolio_"+count+"");
	        img = new Image();					
	        jQuery(img).load(function() {
				jQuery(curr).append(jQuery(this));
	            jQuery(this).css('height', 0);
	        }).attr('src', images[index]);
			
			index++;
			count++;
			
		})
		
		jQuery(".fotospage").animate({ opacity: 1 }, 1000);
		jQuery(".fotospage a").attr("skipclick", 1);
		
		jQuery(this).remove();
		
	})
	
	jQuery('a.color_box').colorbox({slideshow:false});
	max = jQuery('ul.imagegallery li').length;
  
	jQuery(window).resize(function() {

		if (jQuery(document).width() <= screen.width) {
		  var menuulw = 0;
		  jQuerymainNavLi.each(function(){
			  menuulw = menuulw + parseInt(jQuery(this).attr('originalWidth'));
		  })    
		  menuposition = (jQuery(document).width() - (menuulw))/2;    
		  if(!(jQuery(document).width() < menuulw)){
			  jQuerymainNav.css({ left: menuposition });
		  }
		  if (menustatus) {
			  jQuerymagicLine.css({
			    left: jQuerymainNavLi.find("a.active").position().left + menuposition
			  })
			  jQuerymagicLine.attr('magicleft', jQuerymainNavLi.find("a.active").position().left + menuposition);
		  }
		  jQuery("#page").css({"min-width": parseInt(menuulw)+5});
		  if (screenw >= 1600) {	  
			  jQuery("#page").css({ height: parseInt(jQuery(document).height())-23 });
			  jQuery(".hentry").css({ height: parseInt(jQuery(document).height())-50-190 });
		  }
		}
  });

	jQuery('#plupperButton').html(''); 
	plupper.init(jQuery('#plupperaccount').val());
	
  
}


function windowLoad(){
	
	var screenw = screen.width;
	var screenh = screen.height;
	if (screenw >= 1600) {	  
		jQuery("#page").css({ height: parseInt(jQuery(document).height())-23 });
		jQuery(".hentry").css({ height: parseInt(jQuery(document).height())-50-190 });
	}
	
	//HOME PAGE LOAD
	var magicline = jQuery("#magic-line");

	magiclineW = parseInt(magicline.width()) + parseInt(magicline.css("paddingLeft")) + parseInt(magicline.css("paddingRight"));
	jQuery(".hentry").css({ width: parseInt(jQuery("h1#logo").width()) + magiclineW })
	
	if(jQuery("input#page_class").hasClass("home")){
		
		if(!(jQuery.cookie('welcome_text')))	{
			setTimeout(function(){				
				jQuery(".homepresent div").fadeIn(2000, function(){
				setTimeout(function(){
					jQuery("ul.subnav").fadeOut(10);
					jQuery(".homepresent").animate({ left: "100%" }, 3000, function(){jQuery(this).remove();  });
					jQuery.cookie('welcome_text', "turned");
					
				}, 4000)
			})
			}, 1000)	
		}else{
			jQuery("ul.subnav").fadeIn(800);
			jQuery(".lang").slideDown(800);
		}
	}
	else{
		jQuery("ul.subnav").fadeIn(800);
		jQuery(".lang").slideDown(800);
	}
	
	
	if(jQuery("input#page_class").hasClass("fotos")){
		//jQuery(".pageimage").fadeOut(500);
	}
		//POPUP'S POSITION
		_topY = jQuery(".hotel_gallery").height()/2;
		_leftX = jQuery(".hotel_gallery").width()/2;
		jQuery(".hotel_gallery").css({ "marginTop": -_topY, "marginLeft": -_leftX, zIndex: 150 })
		
	
	//ANIAMTE CONTENT ON PAGE LOAD
	jQuery(".hentry").stop().animate({"top": 27}, 800);
	_trigger = true;
	
			
	jQuery("ul.imagegallery li a").hover(function(){
		jQuery(this).find("img").animate({ opacity: 0.5 }, 300);
	}, function(){
		jQuery(this).find("img").animate({ opacity: 1 }, 300);
	})
	
	jQuery("ul.subnav a").click(function() {
    buttonRelPressed = 1;
    buttonRel = jQuery(this).attr('rel');
  })
  
  if (buttonRelPressed == 1) {
    jQuery("ul.subnav a[rel='" + buttonRel + "']").addClass('active');
    buttonRelPressed = 0;
  }
	
	//CLICK ON ALBUM ITEM
	jQuery("ul.albumslist a").click(function(){
		//jQuery("body").append("<div class='gallery_overflow'></div>");
		jQuery("<div class='gallery_overflow'></div>").insertBefore("#content");
		jQuery(".gallery_overflow").css({ opacity: 0, height: jQuery(document).height() })
		jQuery(".gallery_overflow").animate({ opacity: 0.7 })
		var currel = jQuery(this).attr("rel");
		jQuery("#"+currel).find("ul.imagegallery:first").addClass("active");
		jQuery("#"+currel).fadeIn(function(){
			
			jQuery(this).find("ul.imagegallery").css("display", "none");
			jQuery(this).find("ul.imagegallery:first").css("display", "block").addClass("active");
			//jQuery(this).find("ul.imagegallery")removeAttr("id");
			
			secondloadimgs(0,max);
	
			function secondloadimgs(index,max){
				if(jQuery("#"+currel+" ul.imagegallery").hasClass("active")){
					if(index < jQuery("#"+currel+" ul.imagegallery.active li").length){
						jQuery("ul.imagegallery li").removeAttr("id");
						var idcount = 0;
						jQuery("#"+currel+" ul.imagegallery.active li").each(function(){ 
							jQuery(this).attr("id", idcount);
							idcount++;
						 })
						jQuery("#"+currel+" ul.imagegallery.active li#"+index).removeClass("loading");
						jQuery("#"+currel+" ul.imagegallery.active li#"+index).find("img").animate({ top: 0, left: 0, height: 129 }, { duration: 1000, easing: "easeOutElastic"}, { complete: window.setTimeout(function(){secondloadimgs(index + 1, max)}, 100) })
					}
				}		
			}	
			
		});
	})
	
	
	//CLICK ON GALLERY PAGINS
	jQuery("ul.pagings a").click(function(){
		var curpage = jQuery(this).attr("rel");
		var parentdiv = jQuery(this).parents("div.hotel_gallery");
		var prentdivid = parentdiv.attr("id");
		var ullist = parentdiv.find("ul.imagegallery");
		
		
		parentdiv.find("ul.imagegallery.active").removeClass("active")
		parentdiv.find("ul.pagings a.active").removeClass("active");
		jQuery(this).addClass("active");
		jQuery(ullist).fadeOut("fast");
		jQuery(ullist[curpage-1]).fadeIn("slow", function(){
			jQuery(this).addClass("active");
			var max = (parentdiv.find('ul.imagegallery.active li')).length;
			
			secondloadimgs(0,max);
	
			function secondloadimgs(index,max){
				if(jQuery("#"+prentdivid+" ul.imagegallery").hasClass("active")){
					if(index < jQuery("#"+prentdivid+" ul.imagegallery.active li").length){
						jQuery("ul.imagegallery li").removeAttr("id");
						var idcount = 0;
						jQuery("#"+prentdivid+" ul.imagegallery.active li").each(function(){ 
							jQuery(this).attr("id", idcount);
							idcount++;
						 })
						jQuery("#"+prentdivid+" ul.imagegallery.active li#"+index).removeClass("loading");
						jQuery("#"+prentdivid+" ul.imagegallery.active li#"+index).find("img").animate({ top: 0, left: 0, height: 129 }, { duration: 1000, easing: "easeOutElastic"}, { complete: window.setTimeout(function(){secondloadimgs(index + 1, max)}, 100) })
					}
				}		
			}
			
		});
	})
	
	
	//FOTO POPUP EVENTS
	jQuery("a.close").click(function(){
		var currel = jQuery(this).attr("rel");
		jQuery(".gallery_overflow").animate({ opacity: 0 }, function(){ jQuery(this).remove() })
		jQuery("#"+currel).fadeOut();
	})
	
	jQuery("a.tright").click(function(){
		var parentdiv = jQuery(this).parents("div");
		var prentdivid = jQuery(this).parents("div").attr("id");
		var ularray = parentdiv.find("ul.imagegallery");
		var ulcount = 0;
		ularray.each(function(){
			if (ulcount != ularray.length - 1) {
				if (jQuery(this).hasClass("active")) {
					jQuery(this).removeClass("active");
					jQuery(this).fadeOut(10);
					jQuery(ularray[ulcount + 1]).fadeIn(function(){
						jQuery(this).addClass("active");
						var max = (parentdiv.find('ul.imagegallery.active li')).length;
						
						secondloadimgs(0, max);
						
						function secondloadimgs(index, max){
							if (jQuery("#" + prentdivid + " ul.imagegallery").hasClass("active")) {
								if (index < jQuery("#" + prentdivid + " ul.imagegallery.active li").length) {
									jQuery("ul.imagegallery li").removeAttr("id");
									var idcount = 0;
									jQuery("#" + prentdivid + " ul.imagegallery.active li").each(function(){
										jQuery(this).attr("id", idcount);
										idcount++;
									})
									jQuery("#" + prentdivid + " ul.imagegallery.active li#" + index).removeClass("loading");
									jQuery("#" + prentdivid + " ul.imagegallery.active li#" + index).find("img").animate({
										top: 0,
										left: 0,
										height: 129
									}, {
										duration: 1000,
										easing: "easeOutElastic"
									}, {
										complete: window.setTimeout(function(){
											secondloadimgs(index + 1, max)
										}, 100)
									})
								}
							}
						}
					});
					ulcount++;
					jQuery("ul.pagings li a").each(function(){
						if(jQuery(this).hasClass("active"))	{ jQuery(this).removeClass("active") }
						if(jQuery(this).attr("rel") == ulcount+1)	{
							jQuery(this).addClass("active");
						}
					});
				}
			}
			else {
				return;
			}
		})
	})
	
	jQuery("a.tleft").click(function(){
		var parentdiv = jQuery(this).parents("div");
		var prentdivid = jQuery(this).parents("div").attr("id");
		var ularray = parentdiv.find("ul.imagegallery");
		var ulcount = 0;
		ularray.each(function(){
			if (ulcount != ularray.length - 1) {
				if (jQuery(this).hasClass("active")) {
					jQuery(this).removeClass("active");
					jQuery(this).fadeOut(10);
					jQuery(ularray[ulcount + 1]).fadeIn(function(){
						jQuery(this).addClass("active");
						var max = (parentdiv.find('ul.imagegallery.active li')).length;
						
						secondloadimgs(0, max);
						
						function secondloadimgs(index, max){
							if (jQuery("#" + prentdivid + " ul.imagegallery").hasClass("active")) {
								if (index < jQuery("#" + prentdivid + " ul.imagegallery.active li").length) {
									jQuery("ul.imagegallery li").removeAttr("id");
									var idcount = 0;
									jQuery("#" + prentdivid + " ul.imagegallery.active li").each(function(){
										jQuery(this).attr("id", idcount);
										idcount++;
									})
									jQuery("#" + prentdivid + " ul.imagegallery.active li#" + index).removeClass("loading");
									jQuery("#" + prentdivid + " ul.imagegallery.active li#" + index).find("img").animate({
										top: 0,
										left: 0,
										height: 129
									}, {
										duration: 1000,
										easing: "easeOutElastic"
									}, {
										complete: window.setTimeout(function(){
											secondloadimgs(index + 1, max)
										}, 100)
									})
								}
							}
						}
					});
					ulcount++;
					jQuery("ul.pagings li a").each(function(){
						if(jQuery(this).hasClass("active"))	{ jQuery(this).removeClass("active") }
						if(jQuery(this).attr("rel") == ulcount+1)	{
							jQuery(this).addClass("active");
						}
					});
				}
			}
			else {
				return;
			}
		})
	})
	
	

		jQuery('ul.imagegallery li a').colorbox({slideshow:false});	
	
	
	//GALLERY ANIMATION
	var gallink = jQuery("ul.albumslist li a");
	gallink.hover(function(){
		liparent = jQuery(this).parent("li");
		divparents = jQuery(this).parent("li").find("div");
		
		jQuery(this).parent().parent().stop().animate({ "marginLeft": -384 }, 300)
		jQuery(this).parent("li").stop().animate({ "marginRight": 128, "marginLeft": 128 }, 300)
		jQuery(this).parent("li").find("div.w_side").stop().animate({ left: -128 }, 300);
		jQuery(this).parent("li").find("div.n_side").stop().animate({ top: -128 }, 300);
		jQuery(this).parent("li").find("div.e_side").stop().animate({ right: -128 }, 300);
		jQuery(this).parent("li").find("div.s_side").stop().animate({ bottom: -128 }, 300);
		
	}, function(){
		jQuery(this).parent().parent().stop().animate({ "marginLeft": -256 }, 300)
		jQuery(this).parent("li").stop().animate({ "marginRight": 0, "marginLeft": 0 }, 300);
		jQuery(this).parent("li").find("div.w_side").stop().animate({ left: 0 }, 300);
		jQuery(this).parent("li").find("div.n_side").stop().animate({ top: 0 }, 300);
		jQuery(this).parent("li").find("div.e_side").stop().animate({ right: 0 }, 300);
		jQuery(this).parent("li").find("div.s_side").stop().animate({ bottom: 0 }, 300);
	})
	
	
	//BALLON TOOLTIP
	jQuery("ul.subnav li").hover(function(){
		jQuery(this).find("div").show().stop().animate({ top: -50 }, 1000)
	}, function(){
		jQuery(this).find("div").hide().stop().animate({ top: 0 }, 10)
	})
	
	jQuery("ul.referenties_icons li div").each(function(){ 
		jQuery(this).css({ display: "none", left: ((54-jQuery(this).width())/2) })
	})
	
	jQuery("ul.referenties_icons li").hover(function(){
		jQuery(this).find("div")
		.stop()
		//.css({ opacity: 1})
		.css({ display: "block"})
		.animate({ top: -25 }, 800)
	}, function(){
		jQuery(this).find("div").stop().css({ display: "none" }).animate({ top: "10%" }, 10)
	})
	
	
	//MAKE SUBPAGES ACTIVE
	var curbodyid = jQuery("body").attr("id");
	if(curbodyid != ''){jQuery("ul.subnav li").find("a."+curbodyid).addClass("active");}
}



jQuery(window).bind("load", function(){
	
	windowLoad();
	
	var magicline = jQuery("#magic-line");
	var navwrap = jQuery(".nav-wrap");
	var menutop = jQuery("#menu-top-menu");
	
	if (jQuery("input#page_class").hasClass("home")) {
		jQuery("a#current_page_item").addClass("external");
		lpos = jQuery("a#current_page_item").position().left + menuposition;
		navwrap.css({
			width: "100%"
		});
		magicline.css({
			height: 111,
			left: lpos,
			width: jQuery("a#current_page_item").width()
		}).text('');
		menutop.css({
			opacity: 1,
			top: 27
		});
		jQuery("ul.subnav").css({ display: "none" });
	}

})


//PAGE PREOLAD STATUS FUNTION
jQuery.Preloader = function(options) {

	if (!(jQuery.cookie('slider_trigger'))){

		var settings = {
			itemsLoaded     : 0,
			loaded 		    : false,
			items           : new Array(),
    		onBefore        : function() {},
			onAfter         : function() {},
			onError         : function() {},
			barColor        : "#f920a2",
			overlayColor    : "#fff",
			barHeight       : "1px",
			overlay         : "#overlay",
			statusblk       : ".statusblk",
			preloader       : "#preloader",
			siteHolder      : "#page"
    	};

    	if (options) {
        	jQuery.extend(settings, options);
   	 	};

		jQuery("html").css({"overflow" : "hidden"});
		
		jQuery("body").append('<div class="statusblk"><div id="preloader"></div></div>');
		jQuery("body").append('<div id="overlay"></div>');
				
		jQuery(settings.overlay).css({
			"background" : settings.overlayColor,
			"top"        : 0,
			"left"       : 0,
			"position"   : "absolute",
			"width"		 : "100%",
			"height"     : "100%",
			"overflow"   : "hidden",
			"z-index"    : 1000
		});
		
		jQuery(settings.statusblk).css({
			"top"        : "50%",
			"left"       : 0,
			"position"   : "absolute",
			"width"		 : 196,
			"height"     : 13,
			"overflow"   : "hidden",
			"z-index"    : 1001
		});

		jQuery(settings.preloader).css({
			"height"     : settings.barHeight,
			"background" : settings.barColor,
			"float"		 : "left",
			"width"      : 0
		});
		
		settings.onBefore.apply(this);
				
		var winWidth = jQuery(window).width();
		var newLeft = (winWidth / 2) - 100;
		jQuery(settings.statusblk).css("left", newLeft + "px");
		
		function preloadImages() {
			jQuery("body").find("img").each(function() {
				url = jQuery(this).attr("src");
				settings.items.push(url);
				onProgress();
			});
		};
		
		function onProgress() {
			settings.itemsLoaded++;
			animatePreloader();
		};
		
		function animatePreloader() {
			percentage = (settings.items.length / settings.itemsLoaded) * 100;
			newWidth = 184;
			if (percentage > 99) {
				jQuery(settings.preloader).stop().animate({width : newWidth + "px"}, 3000, function() {
					jQuery(settings.overlay).fadeOut(1500, function() {
						jQuery("html").css({ "overflow" : "auto" });					
						jQuery(settings.siteHolder).fadeIn(300, function(){ jQuery(settings.overlay).remove(); });
					});
					settings.onAfter.apply(this);
					jQuery(settings.statusblk).remove();
					jQuery.cookie('slider_trigger', "slidered");
					//jQuery(settings.preloader).animate({"left" : finishLeft}, 1500, "easeOutElastic", function() {
						//jQuery(settings.statusblk).remove();
					//});
				});
			} else {
				jQuery(settings.preloader).stop().animate({width: newWidth + "px"}, 3000);
				jQuery.cookie('slider_trigger', "slidered");
			}
		};
		
		preloadImages();

	}	
	
};
