$(document).ready(function() {
	if ($(window).height() < 800) $('html').addClass('lt-h800');
	else if ($(window).height() > 800 && $(window).height() < 900) $('html').addClass('lt-h900');
	else $('html').addClass('gt-h960');
	
	// init retouch samples
	/* @group Retouching */
    if ($('#container .retouching').length) {
    	$('#before-after').beforeAfter({
    		animateIntro: true,
    		introDelay: 100,
    		introDuration: 500,
    		showFullLinks: false,
    		imagePath: '/wp-content/themes/knrk/images/'
    	});
    
    	$('.thumbs-ct a').click(function() {
    		var id = $(this).attr('id');
    		
    		var before = $('.samples-ct div:nth-child(2)');
    		before.css('backgroundImage', before.css('backgroundImage').replace(/sample[0-9]{2}/, id));
  			var after = $('.samples-ct div:nth-child(3)');
  			after.css('backgroundImage', after.css('backgroundImage').replace(/sample[0-9]{2}/, id));
    	});
    }
	/* @end */

	if ($('#container .browse').length) $('body').addClass('showcase');

	/* @group Backgrounder */
	$(function(){
		$.fn.supersized.options = {  
			startwidth: 1280,  
			startheight: 960,
			vertical_center: 1,
			slideshow: 1,
			navigation: 0,
			thumbnail_navigation: 0,
			transition: 1,
			pause_hover: 0,
			slide_counter: 0,
			slide_captions: 0,
			slide_interval: 30000,
			slides : [
				{image : '/photos/bg/01.jpg', title : '01', url : ''},
				{image : '/photos/bg/02.jpg', title : '02', url : ''},
				{image : '/photos/bg/03.jpg', title : '03', url : ''},				
				{image : '/photos/bg/04.jpg', title : '04', url : ''}
			]
		};
	    $('#supersized').supersized(); 	    
	});
	/* @end */
	
	/* @group Album picker */
	if ($('#container .browse')) {
		$(".dropdown dt a").click(function() {
	        $(".dropdown dd .details").slideToggle();
	    });
	                
	    $(".dropdown dd details li a").click(function() {
	        $(".dropdown dd .details").hide();
	    });
	               
	    $(document).bind('click', function(e) {
	        var $clicked = $(e.target);
	        if (! $clicked.parents().hasClass("dropdown"))
	            $(".dropdown dd .details").hide();
	    });
	    
	    var tw = 0;
		$('#content .body article').each(function() {
			tw += $(this).width() + 20;
		});
	    $('#content .gallery img').each(function(index) {
	    	tw += $(this).width() + 1;
	    });
	    $('#content .scroll-pane .body').css({width: (tw + 80) + 'px'});
	}
	/* @end */
	
	/* @group Scrolling */	
	$('.scroll-pane').each(function() {
		$(this).jScrollPane({
			showArrows: false,
			animateScroll: true,
			horizontalGutter: 40,
			horizontalDragMinWidth: 89,
			horizontalDragMaxWidth: 89
		});
		
		$('.jspHorizontalBar .jspDrag').attr('title', 'Drag Me');
		
		var api = $(this).data('jsp');
		var throttleTimeout;
		$(window).bind('resize', function() {				
			if ($.browser.msie) {
				if (!throttleTimeout) {
					throttleTimeout = setTimeout(
						function() {
							api.reinitialise();
							throttleTimeout = null;
						}, 50);
				}	
			} else {
				api.reinitialise();
			}
		});
		
		$('.border .arrow.left').bind('click', function() {
			api.scrollBy(720, 0);
		});
		$('.border .arrow.right').bind('click', function() {
			api.scrollBy(-720, 0);
		});
		
	});
	/* @end */
		
	/* @group Tooltips */
    $('#container nav a[title]').tipsy({gravity: 'sw', fade: true});
    $('#container .border .icon[title]').tipsy({gravity: 'w', fade: true, html: true, special: 'border-caption', opacity: 1, offset: 5, delayOut: 2000});
    $('#container a[title]').tipsy({gravity: 's', fade: true}); 
    $('#container img[title]').tipsy({gravity: false, fade: true});
	/* @end */
	
	/* @group Animation on homepage */
	$('.homepage article').animate({
		opacity: 1.
	}, 3000);
	/* @end */
	
	/* @group Create Datepicker */
	$('.datepicker').datepicker({
		firstDay: 1,
		dateFormat: 'dd/mm/yy',
		monthNames: ['Leden', 'Únor', 'Březen', 'Duben', 'Květen', 'Červen', 'Červenec', 'Srpen', 'Září', 'Říjen', 'Listopad', 'Prosinec'],
		monthNamesShort: ['Led', 'Úno', 'Bře', 'Dub', 'Kvě', 'Čer', 'Červ', 'Srp', 'Zář', 'Říj', 'Lis', 'Pro'],
		dayNames: ['Neděle', 'Pondělí', 'Úterý', 'Středa', 'Čtvrtek', 'Pátek', 'Sobota'],
		dayNamesShort: ['Ne', 'Po', 'Út', 'St', 'Čt', 'Pá', 'So'],
		dayNamesMin: ['Ne', 'Po', 'Út', 'St', 'Čt', 'Pá', 'So']
	});
});

/* @group Notification */
$(window).load(function() {
	$('.notification').fadeOut(2000);
	$('.scroll-pane').focus();
});
