/**
	To make your life easier, all the scripts that are loaded once the DOM has fully loaded have been written here.
	These scripts are linked to the Explicita LP @ ThemeForest.net by Christopher 'crozer' Honninger
**/

$(document).ready(function() { /* ///// start DOM ready ///// */
				
	/** Big button hover/active effects **/
	$('.button, .buttonHighlight').hover(function() {
		$('.button').addClass('button-hover');
		$('.button, .buttonHighlight').mousedown( function() {
			$('.button').addClass('button-active');
			Cufon.replace('.button-active');
			$(this).mouseup( function() {
				$('.button').removeClass('button-active');
				Cufon.replace('.button');
			});
		});
	}, function() {
		$(this).removeClass('button-hover');
	});
	$('.buttonTrial, .buttonHighlight_trial').hover(function() {
		$('.buttonTrial').addClass('button-hover-trial');
		$('.buttonTrial, .buttonHighlight_trial').mousedown(function() {
			$('.buttonTrial').addClass('button-active-trial');
			Cufon.replace('.button-active-trial');
			$(this).mouseup( function() {
				$('.buttonTrial').removeClass('button-active-trial');
				Cufon.replace('.buttonTrial');
			});
		});
	}, function() {
		$('.buttonTrial').removeClass('button-hover-trial');
	});
	
	/** Image hover effects **/
	if($.support.opacity) {
		$('a.boxedImage, ul.products img').hover(function() {
			$(this).stop().animate({opacity: 0.9, filter: ''}, 300);
			}, function() {
			$(this).stop().animate({opacity: 1, filter: ''}, 300);
		});
	}
	
	/** Tabs functionality **/
	$(function () {
		var tabContainers = $('div.tabs > div');
    
		$('div.tabs ul.tabsNavi a').click(function () {
			tabContainers.hide().filter(this.hash).show();
			
			$('div.tabs ul.tabsNavi a').removeClass('selected');
			Cufon.replace('ul.tabsNavi > li > a' , { fontFamily: 'Ubuntu Regular' });
			$(this).addClass('selected');
			
			return false;
		}).filter(':first').click();
		
		$('ul.tabsNavi > li > a').hover(function() {
			$(this).addClass('tab-hover');
		}, function() {
			$(this).removeClass('tab-hover');
		});
	});
	
	/** IE fixes **/
	if ($.browser.msie && $.browser.version == 8 ) {
		$('div.testimonials ul li div:last-child').addClass('ie-last');
		$('.button_imgPre').toggle(function() { $(this).addClass('button_imgPre-active'); });
		$('.button_imgBuy').toggle(function() { $(this).addClass('button_imgBuy-active'); });
		$('.button_imgTrial').toggle(function() { $(this).addClass('button_imgTrial-active'); });
	}
	/** Safari box-shadow workaround **/
	if ( $.browser.webkit && !$.browser.opera && !$.browser.msie && !$.browser.mozilla ) {
		var userAgent = navigator.userAgent.toLowerCase();
		if ( userAgent.indexOf("chrome") === -1 ) {
			$('div.box, div.boxFooter').css({
				'-webkit-box-shadow':'none',
				'background-color':'#e7e7e7'
			});
		}
	}	
	/** Styleswitcher */
	$('.styleSwitcherClose').toggle(function() {
		$('.styleSwitcher').fadeOut();
		$('.styleSwitcherClose').addClass('styleSwitcherOpen');
	}, function() {
		$('.styleSwitcher').fadeIn();
		$('.styleSwitcherClose').removeClass('styleSwitcherOpen');
	});
	$('li.useImages a').toggle(function() {
		$('body.preOrder a.button').addClass('button_imgPre');
		$('a.buttonBuy').addClass('button_imgBuy');
		$('a.buttonTrial').addClass('button_imgTrial');
		$(this).html('Use CSS');
	}, function() {
		$('body.preOrder a.button').removeClass('button_imgPre');
		$('a.buttonBuy').removeClass('button_imgBuy');
		$('a.buttonTrial').removeClass('button_imgTrial');
		$(this).html('Replace CSS w/ Images');
	});
	$('li.useTooltip a').toggle(function() {
		$('div.bottomArea a.button').addClass('trigger');
	}, function() {
		$('div.bottomArea a.button').removeClass('trigger');
	});
	
	/** Initialize Tipsy **/
	$('.topSocial li a').tipsy({gravity: 's', fade:true});
	$('.paymentMethods').tipsy({gravity: 's', fade:true});
	$('ul.products img').tipsy({gravity: 'e', fade:true});
	$('ul.products li.productsOdd img').tipsy({gravity: 'w', fade:true});
	
	/** Initialize bxSlider **/
	$('.testimonials ul').bxSlider({
		mode: 'horizontal',                 // 'horizontal', 'vertical', 'fade'
		infiniteLoop: true,                 // true, false - display first slide after last
		controls: false,                     // true, false - previous and next controls
		speed: 500,                         // integer - in ms, duration of time slide transitions will occupy
		pager: false,                        // true / false - display a pager
		auto: true,                       // true, false - make slideshow change automatically
		pause: 6000 });
	$('.showcase ul').bxSlider({
		mode: 'horizontal',                 // 'horizontal', 'vertical', 'fade'
		infiniteLoop: true,                 // true, false - display first slide after last
		controls: true,                     // true, false - previous and next controls
		speed: 600,                         // integer - in ms, duration of time slide transitions will occupy
		pager: false,                        // true / false - display a pager
		auto: true,                       // true, false - make slideshow change automatically
		pause: 4000 });
	$('.boxedTestimonial ul').bxSlider({
		mode: 'vertical',                 // 'horizontal', 'vertical', 'fade'
		infiniteLoop: true,                 // true, false - display first slide after last
		controls: false,                     // true, false - previous and next controls
		speed: 400,                         // integer - in ms, duration of time slide transitions will occupy
		pager: false,                        // true / false - display a pager
		auto: true,                       // true, false - make slideshow change automatically
		pause: 6000 
	});
	
	/** Initialize PrettyPhoto **/
	$("a[rel^='prettyPhoto']").prettyPhoto({
		animation_speed: 'fast', /* fast/slow/normal */
		autoplay_slideshow: false, /* true/false */
		opacity: 0.80, /* Value between 0 and 1 */
		show_title: true, /* true/false */
		allow_resize: true, /* Resize the photos bigger than viewport. true/false */
		counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
		theme: 'facebook', /* light_rounded / dark_rounded / light_square / dark_square / facebook */
		hideflash: false, /* Hides all the flash object on a page, set to TRUE if flash appears over prettyPhoto */
		autoplay: true, /* Automatically start videos: True/False */
		modal: false, /* If set to true, only the close button will close the window */
		overlay_gallery: true, /* If set to true, a gallery will overlay the fullscreen image on mouse over */
		keyboard_shortcuts: false /* Set to false if you open forms inside prettyPhoto */
	});
	
}); /* ///// end DOM ready ///// */

$(window).load(function() { /* ///// start WINDOW load ///// */
						
	/** LazyLoad settings **/
	$('img:not(.showcase img)').lazyload({
		placeholder : 'assets/images/lazyload_placeholder.png',      
		effect      : 'fadeIn'
	});
	
	/** Nivo Slider settings **/
    $('#slider').nivoSlider({
        effect:'random', //Specify sets like: 'fold,fade,sliceDown'
        slices:12,
        animSpeed:500, //Slide transition speed
        pauseTime:3000,
        startSlide:0, //Set starting Slide (0 index)
        directionNav:false, //Next & Prev
        directionNavHide:true, //Only show on hover
        controlNav:false, //1,2,3...
        controlNavThumbs:false, //Use thumbnails for Control Nav
        controlNavThumbsFromRel:false, //Use image rel for thumbs
        controlNavThumbsSearch: '.jpg', //Replace this with...
        controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
        keyboardNav:true, //Use left & right arrows
        pauseOnHover:true, //Stop animation while hovering
        manualAdvance:false, //Force manual transitions
        captionOpacity:0.8, //Universal caption opacity
        beforeChange: function(){},
        afterChange: function(){},
        slideshowEnd: function(){}, //Triggers after all slides have been shown
        lastSlide: function(){}, //Triggers when last slide is shown
        afterLoad: function(){} //Triggers when slider has loaded
    });
	
	/** Nivo Slider rounded corners **/
	$('.nivo-slice:first').css({
		'-moz-border-radius-topleft': '4px',
		'-webkit-border-top-left-radius': '4px',
		'border-top-left-radius': '4px',
		'-moz-border-radius-bottomleft': '4px',
		'-webkit-border-bottom-left-radius': '4px',
		'border-bottom-left-radius': '4px'

	});
	$('.nivo-slice:last').css({
		'-moz-border-radius-topright': '4px',
		'-webkit-border-top-right-radius': '4px',
		'border-top-right-radius': '4px',
		'-moz-border-radius-bottomright': '4px',
		'-webkit-border-bottom-right-radius': '4px',
		'border-bottom-right-radius': '4px'

	});
	
}); /* ///// end WINDOW load ///// */
