/*******************************************************************************

  Main JavaScript
  Author: Medio Interactive (http://medio.cz/)

*******************************************************************************/

$(document).ready(function() {

	/* Rounded corners for IE */
	if ($.browser.msie) {

		jQuery.support.borderRadius = false;
		jQuery.each(['BorderRadius','MozBorderRadius','WebkitBorderRadius','OBorderRadius','KhtmlBorderRadius'], function() {
		if(document.body.style[this] !== undefined) jQuery.support.borderRadius = true;
		return (!jQuery.support.borderRadius);
		});

		if($.support.borderRadius) {
	    //
	   } else {
	    // $('.box').append('<span class="tlc" /><span class="trc" /><span class="blc" /><span class="brc" />');
	  }

	}

 /********** Show and hide description **********/
	$('.closer-desc .more-desc').hide();
	$('.collection').hover(
	function() { $(this).children('.closer-desc').children('.more-desc').stop(true, true).show(500); },
	function() { $(this).children('.closer-desc').children('.more-desc').stop(true, true).hide(500); }
	);

  /* Solves transparent black pixels bug */


	/********** Scrollable **********/
	$('.gallery').scrollable({circular:true,keyboard:false});
	$('.gallery-2').scrollable({circular:true,keyboard:false});
	$('a.browse').click(function(e) {
		e.preventDefault();
	});


  /********** Accordion **********/
	$('.accordion').accordion({autoHeight:false});

	/********** Colorbox **********/
 	$('.gallery:not(.collections-not) .items div a').colorbox({transition:'fade'});
 	$('.gallery .items div a').click(function(){
  	$('#cboxContent').focus();
	});
	$('a[rel="cbox"]').colorbox({transition:'fade'});
	$('.left-col a').colorbox();

	/********** Show next level of menu **********/
	$('.next-level').hide();
	$('.show-next').click(function() {
	$('.next-level').toggle('fast');
	$(this).remove();
	});


	/********** Newsletter input value **********/
	var footerInput = $('#frmnewsletterForm-email');
	var origValue = footerInput.attr('value');
	footerInput.focus(function() {
		if (footerInput.val() == origValue) {
			footerInput.val('');
		}
	});

	footerInput.blur(function() {
		if (footerInput.val() == '') {
			footerInput.val(origValue);
		}
	});


	/********** Show and hide submenu **********/
	$('.expand:not(.active) .subnav').hide();
	$('.expand:not(.active)').hover(
	function() { $(this).children('.subnav').stop(true, true).show(500); },
	function() { $(this).children('.subnav').stop(true, true).hide(500); }
	);

	/********** Newsletter form ********/
	Nette.addError = function(elem, message) {
		if (elem.focus) {
			elem.focus();
		}
		if (message) {
			$("#flash-msg").html('').append($("<span>").addClass('flash-msg').text(message).append($("<span>")));
		}
	}

	$("#frm-newsletterForm").focusout(function() {
		$("#flash-msg").html('');
	});

	var submitFnc = function() {
		form = this.form || this;
		if (Nette.validateForm(form)) {
			var form = $(form);
			$.post(form.attr('action'), { email: $("#frmnewsletterForm-email").val(), okSubmit: $("#frmnewsletterForm-okSubmit").val() }, function(data, textStatus) {
				if (typeof(data['message']) !== 'undefined' && textStatus == 'success') {
					$("#flash-msg").html('').append($("<span>").addClass('flash-msg').text(data['message']).append($("<span>"))).delay(2500).fadeOut(500, function() {
						$("#flash-msg").html('');
						$("#flash-msg").show();
					});
				}
			}, 'json');
		}
		return false;
	}

	$("#frm-newsletterForm").submit(submitFnc);
	$("#frm-newsletterForm :submit").click(submitFnc);

	/********* Intro images animation *********/

	$('#intro img:gt(0)').hide();
    setInterval(function() {
      $('#intro :first-child').fadeOut()
         .next('img').fadeIn()
         .end().appendTo('#intro'); },
      3000);
});


// DD_belatedPNG fix for IE6
var PNG_fix_selectors = [
    '.content-top',
    '.content-middle',
    '.content-bottom',
    '.site-name'
];

if (typeof DD_belatedPNG !== 'undefined') {
    DD_belatedPNG.fix(PNG_fix_selectors.join(','));
}

