/**
 * (c) Simon Fakir 2011
 * Labdanum Javascript 
 */

$().ready(function() {
	// initCrossFader();
	initBackground();
	inithoverFader();
	//$('.tipsylnk').tipsy({html:true});
	// $('input.focustip').tipsy({trigger: 'focus', gravity: 'ne', fade: true});
	if ($('#accordion').length > 0) initAccordion();
	$('a[rel*=lightbox]').nyroModal();

});
 var inithoverFader = function () 
 {
 	var hoverIn =   function() {   $(this).animate({opacity: "1"}, 300);  };
 	var hoverOut =   function() {   $(this).animate({opacity: "0.5"}, 300);  };
 	$(".hoverFader").animate({opacity: "0.5"}, 300);
    $(".hoverFader").hover(hoverIn,hoverOut);
 };
 var initCrossFader = function () 
 {
 	var fadeIn =  function() {
		var fade = $('> .hover', this);
 		fade.stop().fadeTo(500, 1);
 	};
 	var fadeOut = function () {
		var fade = $('> .hover', this);
			fade.stop().fadeTo(500, 0);
	};
	$('.crossFader').hover(fadeIn,fadeOut );
	 $('.crossFader > .hover').empty(); 
  

};
var initBackground = function () {
	 var theWindow        = $(window),
            $bg              = $("#bg"),
            aspectRatio      = $bg.width() / $bg.height();

         theWindow.resize(function() {
          if ( (theWindow.width() / theWindow.height()) < aspectRatio ) {
             $bg
               .removeClass()
               .addClass('bgheight');
           } else {
                $bg
                  .removeClass()
                  .addClass('bgwidth');
           }
        }).trigger("resize");


}

var initAccordion = function () {
	/* var nestedAccordion=new TINY.accordion.slider("accordion");
	nestedAccordion.init("acc","h3",0,0,"acc-selected"); */
	
	// Hide all the content except the first 
	// odd = div; even = h3
	$('#accordion div.acc-section').hide();
	
	// Add a padding to the first link

	
	// Add the dimension class to all the content
	$('#accordion div').addClass('dimension');
	
	// Set the even links with an 'even' class
	
	// Set the odd links with a 'odd' class
	
	// Show the correct cursor for the links
	$('#accordion h3').css('cursor', 'pointer');
	
	// Handle the click event
	$('#accordion h3').click( function() {
		// Get the content that needs to be shown
		var cur = $(this).next();
		
		// Get the content that needs to be hidden
		var old = $('#accordion div.acc-section:visible');
		
		// Make sure the content that needs to be shown 
		// isn't already visible
		if ( cur.is(':visible') )
			return false;
		
		// Hide the old content
		old.slideToggle(500);
		
		// Show the new content
		cur.stop().slideToggle(500);
		
		// Animate (add) the padding in the new link
		$(this).stop().addClass("active");
		
		// Animate (remove) the padding in the old link
		old.prev().stop().removeClass("active");
		return false;
	} );


}
