﻿$(function() {
	jQuery.each($("a.email"), function() {
		var tmpLink = $(this).attr('href');
		tmpLink = tmpLink.replace('[snabela]','@');
		tmpLink = tmpLink.replace(/\[\]/ig,".");
		tmpLink = tmpLink.replace('.@.','@');
		$(this).attr('href','mailto:' + tmpLink);
	});
	$("a.external").bind("click", function() {
		
		window.open($(this).attr('href'));
		return false;
		
	});
	
	//traverse active
	jQuery.each($(".menu .active"), function() {
	
		$($(this).parent("ul").parents("li:eq(0)")).parent("ul").parents("li:eq(0)").addClass("active");
		$(this).parent("ul").parents("li:eq(0)").addClass("active");

	});
	$("ul.dropdown li").bind("click", function() {
		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' : 1}, 300); },
			function() { $(this).stop().animate({ 'opacity' : 0.8}, 300); }
		);
		
		// init images

		$.fn.colorbox.settings.transition = "fade";
		$.fn.colorbox.settings.bgOpacity = "0.8";
		$.fn.colorbox.settings.contentCurrent = fLang.m.gal.imageCurrentOutOfTotal;
		$("div.gal a").colorbox();		

		// 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");
					}
				});
			}
		); 
	}


	
	$(".qSubmit")
	.bind('click', function() {
		document.getElementById('searchForm').submit();
	});

	if($("#slider").length>0) {
		$("#slider").easySlider({
			controlsBefore:	'<p id="controls">',
			controlsAfter:	'</p>',
			auto: true, 
			continuous: true
		});
	}
	if($("#slider2").length>0) {
		$("#slider2").easySlider({
			controlsBefore:	'<p id="controls2">',
			controlsAfter:	'</p>',		
			prevId: 'prevBtn2',
			nextId: 'nextBtn2'	
		});			
	}
	
	// $("#bottomIcons").css({ 'bottom' : '-280px', 'display' : 'block', 'left' : Math.ceil($("#inner_cols").offset().left) + 'px'})
	// .animate({
		// 'bottom' : '-40px'

		// },{
		// 'duration' : 1000
	// });
	$("#bottomIcons").css({ 'display' : 'block', 'left' : Math.ceil($("#inner_main").offset().left)-150 + 'px' });
	$(window).bind('resize', function() {
		reposLeftIcons();
	});
});﻿

function reposLeftIcons() {
	$("#bottomIcons").animate({ 'left' : Math.ceil($("#inner_main").offset().left)-150 + 'px' },{ 'duration' : 1500 });
}


function slideSwitch() {
    var $active = $('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');

    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}
