

/** Dropdown **/

$(function(){
	$("ul.sf-menu").supersubs({ 
        minWidth:    12,   // minimum width of sub-menus in em units 
        maxWidth:    27,   // maximum width of sub-menus in em units 
        extraWidth:  1     // extra width can ensure lines don't sometimes turn over 
                           // due to slight rounding differences and font-family 
	}).superfish();         
});


/** Twitter **/

$(function() {
	  $("#twitter").getTwitter({
		  userName: "ChargedPixels",
		  numTweets: 3,
		  loaderText: "Loading tweets...",
		  slideIn: true,
		  showHeading: true,
		  headingText: "Latest Tweets",
		  showProfileLink: true
	  });
});


/** Blockqoute **/

$(function() {
		$('blockquote').quovolver();
});


/** Cycle Slider 1 **/

(function($){ 
	$(function(){
		/** Add the next and previous buttons with JavaScript to gracefully degrade */
		var cycle_container = $('#slide-container');
		cycle_container.append('<div id="cycle-next"></div><div id="cycle-prev"></div>');
		cycle_start(cycle_container, 0);
		/** Restart the slideshow when someone resizes the browser to ensure that sliding distance matches the correct viewport */
		$(window).resize(function(){
			var current_slide = cycle_container.find('.slide:visible').index();
			if(window.console&&window.console.log) { console.log('current_slide'+current_slide); }
			cycle_container.cycle('destroy');
			new_window_width = $(window).width();
			cycle_container.find('.slide').width(new_window_width);
			cycle_start(cycle_container, current_slide);
		});
	});
	/** Cycle configurations */
	function cycle_start(container, index){
		var window_width = $(window).width();
		container.find('.slide').width(window_width);
		if (container.length > 0){
			container.cycle({
				timeout: 8000,
				speed: 600,
				pager: '#cycle-pager',
				slideExpr: '.slide',
				fx: 'scrollHorz',
				easeIn: 'linear',
				easeOut: 'swing',
				startingSlide: index,
				pagerAnchorBuilder: cycle_paginate
			});
		}
	}
	function cycle_paginate(ind, el) {
		return '<a href="#slide-'+ind+'"><span>'+ind+'</span></a>';
	}
})(jQuery);


/** Cycle Slider 2 **/

(function($){ 
	$(function(){
		/** Add the next and previous buttons with JavaScript to gracefully degrade */
		var cycle_container = $('#slide-container-2');
		cycle_container.append('<div id="cycle-next"></div><div id="cycle-prev"></div>');
		cycle_start(cycle_container, 0);
		/** Restart the slideshow when someone resizes the browser to ensure that sliding distance matches the correct viewport */
		$(window).resize(function(){
			var current_slide = cycle_container.find('.slide:visible').index();
			if(window.console&&window.console.log) { console.log('current_slide'+current_slide); }
			cycle_container.cycle('destroy');
			new_window_width = $(window).width();
			cycle_container.find('.slide').width(new_window_width);
			cycle_start(cycle_container, current_slide);
		});
	});
	/** Cycle configurations */
	function cycle_start(container, index){
		var window_width = $(window).width();
		container.find('.slide').width(window_width);
		if (container.length > 0){
			container.cycle({
				timeout: 8000,
				speed: 600,
				pager: '#cycle-pager',
				slideExpr: '.slide',
				fx: 'fade',
				easeIn: 'linear',
				easeOut: 'swing',
				startingSlide: index,
				pagerAnchorBuilder: cycle_paginate
			});
		}
	}
	function cycle_paginate(ind, el) {
		return '<a href="#slide-'+ind+'"><span>'+ind+'</span></a>';
	}
})(jQuery);





/** Contact Form **/

$(document).ready(function () {
    $('form#contact-form').submit(function () {
        $('form#contact-form .error').remove();
        var hasError = false;
        $('.requiredField').each(function () {
            if (jQuery.trim($(this).val()) == '') {
                var labelText = $(this).prev('label').text();
                $(this).parent().append('<div class="error">Must enter ' + labelText + '</div>');
                $(this).addClass('inputError');
                hasError = true;
            } else if ($(this).hasClass('email')) {
                var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
                if (!emailReg.test(jQuery.trim($(this).val()))) {
                    var labelText = $(this).prev('label').text();
                    $(this).parent().append('<div class="error">Invalid ' + labelText + '</div>');
                    $(this).addClass('inputError');
                    hasError = true;
                }
            }
        });
        if (!hasError) {
            $('form#contact-form input.submit').fadeOut('normal', function () {
                $(this).parent().append('');
            });
            var formInput = $(this).serialize();
            $.post($(this).attr('action'), formInput, function (data) {
                $('form#contact-form').slideUp("fast", function () {
                    $(this).before('<div class="success">Your email was sent. We will contact you ASAP.</div>');
                });
            });
        }

        return false;

    });
});


/** Pretty Hover **/

$(document).ready(function(){									
	$('.blog-post-image-wrapper').hover(
		function(){
			$(this).find('a img').animate({opacity: ".6"}, 500);		
			$(this).find('.zoom').animate({top:"-150px"}, 500);			
		}, 
		function(){
			$(this).find('a img').animate({opacity: "1.0"}, 500);					
			$(this).find('.zoom').animate({top:"85px"}, 500);
		});			
});
	

/** Pretty Photo **/

$(function() {
	$("area[rel^='prettyPhoto']").prettyPhoto();
	
	$(".gallery:first a[rel^='prettyPhoto']").prettyPhoto({animation_speed:'normal',theme:'light_square',slideshow:3000, autoplay_slideshow: false});
	$(".gallery:gt(0) a[rel^='prettyPhoto']").prettyPhoto({animation_speed:'fast',slideshow:10000, hideflash: true});

	$("#custom_content a[rel^='prettyPhoto']:first").prettyPhoto({
		custom_markup: '<div id="map_canvas" style="width:260px; height:265px"></div>',
		changepicturecallback: function(){ initialize(); }
	});

	$("#custom_content a[rel^='prettyPhoto']:last").prettyPhoto({
		custom_markup: '<div id="bsap_1259344" class="bsarocks bsap_d49a0984d0f377271ccbf01a33f2b6d6"></div><div id="bsap_1237859" class="bsarocks bsap_d49a0984d0f377271ccbf01a33f2b6d6" style="height:260px"></div><div id="bsap_1251710" class="bsarocks bsap_d49a0984d0f377271ccbf01a33f2b6d6"></div>',
		changepicturecallback: function(){ _bsap.exec(); }
	});
});


/** Accordion **/

$(function() {
	//Set default open/close settings
	$('.acc_container').hide(); //Hide/close all containers
	/*$('.acc_trigger:first').addClass('active').next().show();*/ //Add "active" class to first trigger, then show/open the immediate next container
	
	//On Click
	$('.acc_trigger').click(function(){
		if( $(this).next().is(':hidden') ) { //If immediate next container is closed...
			$('.acc_trigger').removeClass('active').next().slideUp(); //Remove all "active" state and slide up the immediate next container
			$(this).toggleClass('active').next().slideDown(); //Add "active" state to clicked trigger and slide down the immediate next container
		}
		return false; //Prevent the browser jump to the link anchor
	});
});


/** Roundabout slider **/

$(function() {
      $('ul#myRoundabout').roundabout({
		 minOpacity: 0.3, // invisible!
         minScale: 0.65, // tiny!
		 duration: 500
      });
});





