﻿$(function() {

	jQuery.each($("a.email"), function() {
		var tmpLink = $(this).attr('href');
		if(!tmpLink) tmpLink = $(this).html();
		tmpLink = tmpLink.replace('[snabela]','@');
		tmpLink = tmpLink.replace(/\[\]/ig,".");
		tmpLink = tmpLink.replace('.@.','@');
		$(this).attr('href','mailto:' + tmpLink)
		if(!$(this).hasClass('noTxt')) {
			$(this).html(tmpLink);
		}
		if($(this).hasClass('noLink')) {
			$(this).replaceWith(tmpLink);
		}
	});
	
	$("a.external,area.external").bind("click", function() {
		
		window.open($(this).attr('href'));
		return false;
		
	});
	
	//traverse active
	$("li.active").parents('li').addClass('active');
	

	
	$("ul.dropdown li").bind("click", function(e) {
		e.stopPropagation(); 
		var linkObj = $(this).find("a");
		if($(linkObj).attr('href')!="") {
			if($(linkObj).hasClass('external')) {
				window.open($(linkObj).attr('href'));
			} else {
				document.location.href = $(linkObj).attr('href');
			}
		}
	
	});
	

	// gallery start
	if($("div.gal").length>0) {
		
		$("#gal_switch_label").html(fLang.m.gal.switchView);
		
		// gallery type 1
		//$("div.gal img").css("opacity",0.8);
		$("div.gal img").hover(
			function() { $(this).stop().animate({ 'opacity' : 0.8}, 300); },
			function() { $(this).stop().animate({ 'opacity' : 1}, 300); }
		);
		
		// init images

		$.fn.colorbox.settings.transition = "none";
		$.fn.colorbox.settings.opacity = "1";
		$.fn.colorbox.settings.current = fLang.m.gal.imageCurrentOutOfTotal;
		$("div.gal a").colorbox({transition:"none", width:"80%", height:"95%"});
	

		// switch view		
		$("a.switch_thumb").toggle(
			function(){
				$(this).addClass("swap");
				$("ul.display").fadeOut("fast", function() {
					if($("ul.display").hasClass("thumb_view")) {
						$(this).fadeIn("fast").removeClass("thumb_view");
					} else {
						$(this).fadeIn("fast").addClass("thumb_view");
					}
				});
			}, 
			function () {
				$(this).removeClass("swap");
				$("ul.display").fadeOut("fast", function() {
					if($("ul.display").hasClass("thumb_view")) {
						$(this).fadeIn("fast").removeClass("thumb_view");
					} else {
						$(this).fadeIn("fast").addClass("thumb_view");
					}
				});
			}
		); 
	}

	$("a.gal").colorbox({transition:"none", width:"80%", height:"95%"});
	
	// init menus
	var tmp = location.href;
	if(tmp.substring(tmp.length-1,tmp.length)=="/") {
		$(".menu_custom")
		.css({ 'top' : '-5px' })
		.animate(
			{ 'top': '-18px' },
			{ duration: 500, easing: 'easeOutCirc' }	
		);
	} 	
	m_galBox_init();
});﻿


var box_boxes = [];
function m_galBox_init() {
	var boxes = ["white","white","white","black","white","white","white","black","white","white","white",,"white","white","white"];
	var totalNumberOfGridSpots = 17;
	var avoidSpots = "|5|6|7|";
	var contObj = $("div.m.galBox_container");
	var occupiedSpaces = ",";
	var gridBoxes = [];
	// create grid
	$(contObj).append("<div class=\"grid\"></div>");
	var gridObj = $(contObj).find(".grid");
	for(var i = 0; i < boxes.length; i++) {
		var tmpClass = boxes[i];
		var rand = Math.floor(Math.random()*totalNumberOfGridSpots);
		var isOccupied = true;
		while (isOccupied==true) {
			if(occupiedSpaces.indexOf("," + rand + ",")<0) {
				isOccupied = false;
			} else {
				rand = Math.floor(Math.random()*totalNumberOfGridSpots);
			}
		}
		// add rand box
		gridBoxes[rand] = "<div class=\"" + tmpClass + "\" id=\"box_" + rand + "\"></div>";
		occupiedSpaces = occupiedSpaces + rand + ",";
		box_boxes[i] = rand;
	}
	for(var i=0; i < totalNumberOfGridSpots; i++) {
		if(!gridBoxes[i]) {
			gridBoxes[i] = "<div class=\"filler\" id=\"box_" + i + "\"></div>";
		}	
	}	
	
	var tmp = "";
	for(var i=0; i < gridBoxes.length; i++) {
		tmp += gridBoxes[i];
	}
	$(gridObj).append(tmp);
	
	//fadeout
	$(gridObj).find("div[class!=filler]").css('opacity',0);
	
	// start looping
	m_galBox_start();
}

function m_galBox_start() {
	var currNr = Math.floor(Math.random()*box_boxes.length);
	var currBox = box_boxes[currNr];
	$("#box_" + currBox)
	.animate({ 'opacity' : 0.4},{ duration: 800, easing: 'easeOutQuad' })
	.animate({ 'opacity' : 0},{ duration: 1500, easing: 'easeOutQuad',
		complete: function() {
			m_galBox_start();
		}
	});
	

}









