/* ----------------------------------------------------------------- */
/*     JS developed by Smartforce.ch                                 */
/*     SF 2011.1                                                     */
/* ----------------------------------------------------------------- */

//<![CDATA[
$(document).ready(function() {
	
	
	/* ----------------------------------------------------------------- */
	/* Generic START --------------------------------------------------- */
	/* ----------------------------------------------------------------- */
	
	/* ----------------------------------------------------------------- */
	/* Generic END ----------------------------------------------------- */
	/* ----------------------------------------------------------------- */
	
	$("#featureBox .leftBox, #featureBox .centerBox, #featureBox .rightBox").hover(function() {
		// Stuff to do when the mouse enters the element;
		$(this).not(".selected").addClass("hover");
	}, function() {
		// Stuff to do when the mouse leaves the element;
		$(this).removeClass("hover");
	});
	
	// Credits: Robert Penners easing equations (http://www.robertpenner.com/easing/).
	jQuery.easing['BounceEaseOut'] = function(p, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	};
	
	// Callback (external controls, jcarousel)
	function mycarousel_initCallback(carousel) {
		$('.jcarousel-control div').bind('click', function() {
			carousel.scroll($.jcarousel.intval($(this).find("a").attr("name")));
			$(this).siblings().removeClass("selected");
			$(this).removeClass("hover");
			$(this).addClass("selected");
			return false;
		});
	}
	
	// jCarousel
    $('#mycarousel').jcarousel({
        // Configuration goes here
		scroll: 1,
		easing: 'BounceEaseOut',
		initCallback: mycarousel_initCallback,
		// This tells jCarousel NOT to autobuild prev/next buttons
		buttonNextHTML: null,
		buttonPrevHTML: null,
		animation: 700,
		itemFallbackDimension: 780
    });
	
	// Showcase
	
	// Hover
	$(".showcaseIndex ul li a").hover(function(){
		$(this).addClass("hover");
	},function(){
		$(this).removeClass("hover");
	});
	
	
	$('.showcaseLoader').hide();
	
	// Simulate Click
	// $(".showcaseIndex ul li:first a").click();
	
	// Click
	$(".showcaseIndex ul li a").click(function(event){
		event.preventDefault();
		
		//save this!!!
		var thisClickNowElement = $(this);
		
		$(".showcaseIndex ul li a").parent().andSelf().removeClass("active");
		$(this).parent().andSelf().addClass("active");
		
		var showcaseUrl = $(this).attr("href");
		
		$.ajax({
			url: showcaseUrl,
			success: function(data) {
				$('.showcaseContent').html(data);
				$('.showcaseLoader').hide();
				$('.showcaseContent').show();
			},
			beforeSend: function(){
				// Handle the beforeSend event
				$('.showcaseContent').hide();
				$('.showcaseLoader').show();
				
			},
			complete: function(){
				// Handle the complete event
				$('.showcaseLoader').hide();
			}
			
		});
		return false;
	});
	
	$(".showcasePic").live('hover', function() {
		$(this).toggleClass("hover");
	});
	
	$(".showcasePic").live('click', function() {
		var showcaseLink = $(".showcaseLink").find("a").attr("href");
		if(showcaseLink){
			console.log(showcaseLink);
			document.location = showcaseLink;
		}
		
		
	});
	
	
});
//]]>
