$(document).ready(function(){
	//jump to panel 2 - the home panel
	$('#scroller' ).scrollTo("#home", 0 );

	//open links in new page
    $('a[href^="http://"]').attr("target", "_blank");

	//fade the menu buttons up and down
	$(".button").click(function(){
		var divname= this.name;
		$("#"+divname).fadeIn(0).siblings('.button_active').fadeOut(1300);
	});

	//check if there's a hash and put button3 on top
	var hash = window.location.hash;
	hash = hash.substring(1);
	if(hash=="")
	{
		$("#home_button3").css("display","block");
	}
	if(hash=="home")
	{
		$("#home_button3").css("display","block");
	}
	else if(hash=="about_us")
	{
		$("#about_us_button3").css("display","block");
	}
	else if(hash=="portfolio")
	{
		$("#portfolio_button3").css("display","block");
	}
	else if(hash=="services")
	{
		$("#services_button3").css("display","block");
	}
	else if(hash=="testimonials")
	{
		$("#testimonials_button3").css("display","block");
	}
	else if(hash=="contact_us")
	{
		$("#contact_us_button3").css("display","block");
	}
	else if(hash=="login")
	{
		$("#login_button3").css("display","block");
	}
	
	//load the portfolio fade rotate
	jQuery(document).ready(function(){
		jQuery('#portfolio_rotate').fadeSlideShow({
			speed: 900, // default animation transition speed
			interval: 4000 // default interval between image change
		});
	});
	
	//load the testimonials fade rotate
	(function($) {
		function init() {
		  $("#testimonials_rotate").fadeTransition(
			{pauseTime: 3000,
			 transitionTime: 900,
			 delayStart: false,
			 manualNavigation: true,
			 pauseOnMouseOver: true,
			 createNavButtons: true});}
		$(document).ready(init);
	})(jQuery);
	
	//hide the email address from spambots
	$(function(){
		var spt = $('span.email');
		var at = / at /;
		var dot = / dot /g;
		var addr = $(spt).text().replace(at,"@").replace(dot,".");
		$(spt).after('<a id="email" href="mailto:'+addr+'" title="Send us an email"></a>')
		.hover(function(){window.status="Send an email";}, function(){window.status="";});
		$(spt).remove();
	});
	
	//bookmark the page
	$("#login_message_click").jBrowserBookmark();
	
	//Scrollto settings
	$('body').serialScroll({
        target:'#scroller',
        items:'.panel', // Selector to the items ( relative to the matched elements, '#sections' in this case )
        axis:'xy',// The default is 'y' scroll on both ways
        navigation:'#menu a',
        duration:1200,// Length of the animation (if you scroll 2 axes and use queue, then each axis take half this time)
        force:false, // Force a scroll to the element specified by 'start' (some browsers don't reset on refreshes)
        constant:true, // constant speed
		lock:false,
		stop:true,
        onBefore:function( e, elem, $pane, $items, pos ){
             //those arguments with a $ are jqueryfied, elem isn't.
            e.preventDefault();
            if( this.blur )
                this.blur();
        },
        onAfter:function( elem ){
            //'this' is the element being scrolled ($pane) not jqueryfied
        }
    });
    
    $.localScroll({
        hash:true
	});
	
	
	//extra scrollto links
	$(".link_about_us").click(function() {
    	$('#scroller').trigger( 'goto', [ 2 ] );
		var divname= this.name;
		$("#"+divname).fadeIn(0).siblings('.button_active').fadeOut(1300);
 	});
	
	$(".link_portfolio").click(function() {
    	$('#scroller').trigger( 'goto', [ 3 ] );
		var divname= this.name;
		$("#"+divname).fadeIn(0).siblings('.button_active').fadeOut(1300);
 	});
	
	$(".link_services").click(function() {
    	$('#scroller').trigger( 'goto', [ 4 ] );
		var divname= this.name;
		$("#"+divname).fadeIn(0).siblings('.button_active').fadeOut(1300);
 	});
	
	$(".link_testimonials").click(function() {
    	$('#scroller').trigger( 'goto', [ 5 ] );
		var divname= this.name;
		$("#"+divname).fadeIn(0).siblings('.button_active').fadeOut(1300);
 	});
	
	$(".link_contact_us").click(function() {
    	$('#scroller').trigger( 'goto', [ 6 ] );
		var divname= this.name;
		$("#"+divname).fadeIn(0).siblings('.button_active').fadeOut(1300);
 	});
	
	//columns
	$(function () {
		$(".services_text").columnize({
			columns: 2, 
			balance: false,
			height:280
		});
	});
	
	//hide the services that are faded down
	$(function(){
		$("#text_updatable_websites").fadeOut(0);
		$("#text_hosting").fadeOut(0);
		$("#text_everything").fadeOut(0);
	});
    
    //SNOWFALL
    $("#christmas_button_on").click(function(){
        $("#christmas_button_on").fadeOut(0);
        $(document).snowfall('clear');
        $(document).snowfall({round:true, flakecount:11900, minSize: 5, maxSize:8}); // add rounded
    });
    
    $("#christmas_button_off").click(function(){
        $("#christmas_button_on").fadeIn(0);
        $(document).snowfall('clear');
    });
    
});
