/*
	Name: scripts.js
	Date: March 2010
	Description: Global Scripts for Chaudigital.
	Version: 1.0
	Coder: Enrique Ramirez
	Coder URI: http://enrique-ramirez.com
*/

/* Setting NoConflict mode */
var $j = jQuery.noConflict();

$j(document).ready(function(){
	
	/* Dropdowns
	-----------------------------------------------*/
	$j("#header .nav .drop").parent().hover(
		function() {
			$j(this).children('.drop').show();
		},
		function() {
			$j(this).children('.drop').hide();
		}
	);
	
	// Slight help for IE
	$j("#header .nav .drop ul li:nth-child(2n+1)").css('clear','left')

	/* Top Menu
	-----------------------------------------------*/
	//$j("#top .cont").wrap('<div class="cont-wrap" />');
	
	// Hiding
	$j("#top .cont-wrap").hide();
	
	// Adding Close Button
	$j("#top .cont").append('<span class="close">x</span>');
	
	/* Show/hide
	*******************************/
	$j("#excerpt .btn").live('click', function() {
		if ($j("#top .cont-wrap").is(':hidden')) {
			$j("#top .cont-wrap").slideDown({
				duration: 1100,
				easing: 'easeOutQuad'
			});
		} else {
			$j("#top .cont-wrap").slideUp({
				duration: 900,
				easing: 'easeOutQuad'
			});
		}
		
		return false;
	});
	
	// Close Button
	$j("#top .close").live('click', function() {
		$j("#top .cont-wrap").slideUp({
			duration: 900,
			easing: 'easeOutQuad'
		});
		
		return false;
	});
	
	/* Slides
	-----------------------------------------------*/
	// Adding gigantosaurically long div
	$j("#services").wrapInner('<div id="slider" />');
	
	// Setting first slide as active
	$j("#services-tabs li:first-child").addClass('active');

	// Getting total width and height
	var totalWidth = 0;
	var totalHeight = $j("#services .slide:first-child").height();
	$j("#slider .slide").each(function() {
		totalWidth += $j(this).outerWidth(true);
	});
	$j("#slider").width(totalWidth);
	$j("#services").height(totalHeight);

	/* Sliding
	*******************************/
	$j("#services-tabs a").live('click', function() {
		// Finding slide
		var currentslide = $j(this).attr("href");
		var position = $j(currentslide).position().left;

		// Setting current tab
		$j("#services-tabs li").removeClass('active');
		$j(this).parent().addClass('active');

		// Animating
		$j("#slider").stop().animate({marginLeft: -position}, 1200, 'easeOutCubic');

		// Changing wrapper height
		var slideHeight = $j(currentslide).height();
		$j("#services").stop().animate({height: slideHeight}, 800, 'easeOutCubic');

		// Hold your horses, cowboy!
		return false;
	});
	
	/* Lightbox
	-----------------------------------------------*/
	$j("a[rel=gallery]").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'outside'
	});
	
	/* Product Tabs
	-----------------------------------------------*/
	// Adding gigantosaurically long div
	$j("#product-tabs .slider-wrap").wrapInner('<div class="slider" />');
	
	// Setting first slide as active
	$j("#product-tabs .tabs li:first-child").addClass('active');

	// Getting total width and height
	var prodTotalWidth = 0;
	var prodTotalHeight = $j("#product-tabs .slider .slide:first-child").height();
	
	$j("#product-tabs .slide").each(function() {
		prodTotalWidth += $j(this).outerWidth(true);
	});
	$j("#product-tabs .slider").width(prodTotalWidth);
	$j("#product-tabs .slider-wrap").height(prodTotalHeight);

	/* Sliding
	*******************************/
	$j("#product-tabs .tabs li a").live('click', function() {
		// Finding slide
		var prodCurrentslide = $j(this).attr("href");
		var prodPosition = $j(prodCurrentslide).position().left;

		// Setting current tab
		$j("#product-tabs .tabs li").removeClass('active');
		$j(this).parent().addClass('active');

		// Animating
		$j("#product-tabs .slider").stop().animate({marginLeft: -prodPosition}, 1350, 'easeOutCubic');

		// Changing wrapper height
		var prodSlideHeight = $j(prodCurrentslide).height();
		$j("#product-tabs .slider-wrap").stop().animate({height: prodSlideHeight}, 1000, 'easeOutCubic');

		// Hold your horses, cowboy!
		return false;
	});
	
});
