$(function(){   

	// — — — — — — — — — — — —  BEGIN START CODE — — — — — — — — — — — — 
    
	/*
	$(document).keydown(function(e) {
		switch(e.which) {
			case 37:	 $('div#section_content span#sliderprev a').click(); break;	// left arrow key
			case 39:	 $('div#section_content span#slidernext a').click(); break;	// right arrow key
		}
	});
	*/
	
    $(document).keypress(function(e) {
		switch(e.which) {
			case 97:	 $('div#section_content span#sliderprev a').click(); break;	// A key
			case 115:	 $('div#section_content span#slidernext a').click(); break;	// S key
			case 13:	 $('div#section_content span#slidernext a').click(); break;	// return key
			case 9:	 $('div#section_content span#slidernext a').click(); break;	// tab key
		}
	});
	
	
    $(document).keypress(function(e) {
		switch(e.which) {
			case 53:	 $('div#design.red_button').click(); break;	// number 5 key
			case 54:	 $('div#graphics.red_button').click(); break;	// number 6 key
			case 55:	 $('div#drawings.red_button').click(); break;	// number 7 key
			case 56:	 $('div#mixed.red_button').click(); break;	// number 8 key
			case 57:	 $('div#photo.red_button').click(); break;	// number 9 key
			case 48:	 $('div#code.red_button').click(); break;	// number 0 key
		}
	});
	
    $(document).keypress(function(e) {
		switch(e.which) {
			case 49:	 $('div#button_blue').click(); break;	 // number 1 key
			case 50:	 $('div#button_red').click(); break; // number 2 key
			case 51:	 $('div#button_purple').click(); break; // number 3 key
			case 52:	 $('div#button_green').click(); break; // number 4 key
		}
	});

    // preload function
    jQuery.preloadImages = function() {
        for(var i = 0; i<arguments.length; i++) {
            jQuery("<img>").attr("src", arguments[i]);
        }
    }
    
    // lets preload some images
    $.preloadImages("images/icons/zoomin_active.png", "images/icons/zoomout.png", "images/icons/zoomout_active.png", "images/palette/sidebar/blue.png", "images/palette/sidebar/purple.png", "images/palette/sidebar/red.png", "images/palette/sidebar/green.png", "images/palette/blue_dark.png", "images/palette/purple_dark.png", "images/palette/red_dark.png", "images/palette/green_dark.png", "images/core/white_fadeout.png");
    
    // hide loading spinner
    $('#loading').hide(); 
    
	// — — — — — — — — — — — —  END START CODE — — — — — — — — — — — — 
	
	// — — — — — — — — — — — —  START BUTTON BLUE — — — — — — — — — — — 
	
    $("#button_blue").click(function(){
        $("#pagepermalink").attr("href", "http://www.leomancinidesign.com/blog");
        var defaultpage = $("#title").attr("class");
        $('#content').fadeOut();  
        $('#clientele').fadeOut("slow");  
		$("#right").animate({marginLeft:'-251px'},'slow');		
        $("#button_blue").addClass("selected");
        $("#button_purple").removeClass("selected");
        $("#button_red").removeClass("selected");
        $("#button_green").removeClass("selected");
        $(this).delay(500,function(){
            $("#content").addClass("blue").removeClass("purple").removeClass("red").removeClass("green");
            $("#sidebar").addClass("blue").removeClass("purple").removeClass("red").removeClass("green");
        });
        $(this).delay(500,function() {
            $.get("content/blue.php?post=" + defaultpage, function(data){
                $(this).delay(200,function(){
                        $.get("content/sidebar/blue.php?post=" + defaultpage, function(data){
                            $("#content").css("overflow", "visible");
                            $('#sidebar').empty().html(data);
                            $("#phone").live("click", function(){
                                $("#phone").html('<img src="images/icons/phone_16.png" class="smallicon_contact">718 440 1964').attr("id", "phone_back");
                            });
                            $("#phone_back").live("click", function(){
                                $("#phone_back").html('<img src="images/icons/phone_16.png" class="smallicon_contact">phone').attr("id", "phone");
                            });
                            $("#title").attr("class", "BLOGHOME");
                        });
                    $('#content').empty().html(data).hide();     
                    $('#content').fadeIn();  
                    $("a.fancybox").fancybox({
                        'overlayOpacity': '0.8',
                        'imageScale': false,
                        'centerOnScroll': false
                    });
                    $(".more_posts").click(function(){
                        $("#content").css("overflow", "visible");
                        $("#blogpost").css("overflow", "visible");
                        $("#left").css("overflow", "visible");
                        $("#blue_default_fade").hide();
                        $("#homeblogheader").show("slow");
                        $("#longposts").show();
                        $("#shortposts").hide()
                        $("#welcome").animate({height: '0px', marginBottom: '15px'},500);
                        $(".i").fadeOut();	
                        $(this).delay(400,function(){
                            $("#welcome").fadeOut().empty();	
                        });
                    });
                    
                    $("#hire").click(function(){
                        $(this).append("I'm currently only available for small freelance jobs.");
                    });
                });
            });  
        });
        $(this).delay(1800,function(){
            $("#right").animate({marginLeft:'0px'},'slow');	
        });
        $("#title").attr("class", "");
	});		
	
	// — — — — — — — — — — — —  END BUTTON BLUE — — — — — — — — — — — — 
	
	// — — — — — — — — — — — —  BEGIN LIVE FUNCTIONS — — — — — — — — — — — 

	$(".secondclientclick").live("click", function() {
        var defaultpage = client;
        var client = $(this).attr("id");
        $.get("content/purple.php?client=" + client, function(data){
            $('#content').fadeOut();
            $('#clientele').fadeOut();  
            $(this).delay(500,function(){
                $('#clientele').empty().html(data);     
                $('#clientele').fadeIn();  
                $('#content').fadeIn();  
            });
        });
	});		
                
    $("a.clientbox").livequery( function(){	
		$(this).fancybox({ 
            'overlayOpacity': '0.8',
            'imageScale': false,
            'centerOnScroll': false
        });
	});
	
    $("#backtoclientlist").live("click", function() {
        $("#button_purple").click();
    });
    
	// — — — — — — — — — — — —  END LIVE FUNCTIONS — — — — — — — — — — — — 
	
	// — — — — — — — — — — — —  START BUTTON PURPLE — — — — — — — — — — — 
	
    $("#button_purple").live("click", function() {
        $('#comments').hide();  
        $("#left").animate({paddingBottom: "0px",height: "325px"},'slow');
        $("#blogpost").animate({paddingBottom: "0px",height: "300px"},'slow');
        $("#content").animate({paddingBottom: "0px",height: "300px"},'slow');
        var defaultpage = $("#title").attr("class");
        if(defaultpage == "BLOGHOME") { defaultpage = ""; }
        if(defaultpage == "none") { defaultpage = "purple"; }
        $('#content').fadeOut();  
        $('#clientele').fadeOut();  
        $("#button_blue").removeClass("selected");
        $("#button_purple").addClass("selected");
        $("#button_red").removeClass("selected");
        $("#button_green").removeClass("selected");
        $(this).delay(500,function(){
                $("#content").removeClass("blue").addClass("purple").removeClass("red").removeClass("green");
                $("#sidebar").removeClass("blue").addClass("purple").removeClass("red").removeClass("green");
        });       
        $("#right").animate({marginLeft:'-251px'},'slow');	
        $(this).delay(1800,function(){
            $("#right").animate({marginLeft:'0px'},'slow');	
        });
        $.get("content/purple.php?defaultpage=" + defaultpage, function(data) {
            $(this).delay(200,function() {
                if(defaultpage == "purple") {
                    purplesidebar = "purple.php?moreclients=0&defaultpage=" + defaultpage;
                    $("#pagepermalink").attr("href", "http://www.leomancinidesign.com/clients");
                }
                if(defaultpage != "purple") {
                    if(defaultpage == "") {
                        purplesidebar = "purple.php?moreclients=0&defaultpage=" + defaultpage;
                        $("#pagepermalink").attr("href", "http://www.leomancinidesign.com/clients");
                    } else {
                        purplesidebar = "clientinfo.php?client=" + defaultpage;
                        $("#pagepermalink").attr("href", "http://www.leomancinidesign.com/client:" + defaultpage);
                    }
                }
                $.get("content/sidebar/" + purplesidebar, function(data) {
                    $('#sidebar').empty().html(data);
                    $(".clientclick").click(function() {     
                        $("#right").animate({marginLeft:'-251px'},'slow');	
                        $(this).delay(1800,function(){
                            $("#right").animate({marginLeft:'0px'},'slow');	
                        });
                        $('#content').fadeOut();  
                        $('#clientele').fadeOut();  
                        var client = $(this).attr("id");
                        var defaultpage = client;
                        $("#pagepermalink").attr("href", "http://www.leomancinidesign.com/client:" + client);
                        $.preloadImages("images/clientele/" + client + "_website_big.png", "images/clientele/" + client + "_website.png", "images/clientele/" + client + "_logo.png", "images/clientele/" + client + ".png");
                        $.get("content/purple.php?client=" + client + "&defaultpage=" + defaultpage, function(data){
                            $('#content').fadeOut();
                            $('#clientele').fadeOut();                                  
                            $('#clientele').empty().html(data);  
                            $('#content').fadeIn();
                            $('#clientele').fadeIn();
                        });
                        $.get("content/sidebar/clientinfo.php?client=" + client, function(data){
                            $('#sidebar').empty().html(data);
                            $(".secondclientclick").click(function() {
                                var defaultpage = client;
                                var client = $(this).attr("id");
                                $.get("content/purple.php?client=" + client, function(data){
                                    $('#content').fadeOut();
                                    $('#clientele').fadeOut();  
                                    $(this).delay(500,function(){
                                        $('#clientele').empty().html(data);     
                                        $('#clientele').fadeIn();  
                                        $('#content').fadeIn();  
                                    });
                                });
                            });
                        });
                    });
                    $(".moreclients").click(function(){
                        $("#right").animate({marginLeft:'-251px'},'slow');	
                        $(this).delay(1800,function(){
                            $("#right").animate({marginLeft:'0px'},'slow');	
                        });
                        var number = $(this).attr("id");
                        $(this).delay(500,function(){
                            $.get("content/sidebar/purple.php?moreclients=" + number, function(data){
                                $('#sidebar').empty().html(data);
                                            $(".clientclick").click(function() {     
                                                $("#right").animate({marginLeft:'-251px'},'slow');	
                                                $(this).delay(1800,function(){
                                                    $("#right").animate({marginLeft:'0px'},'slow');	
                                                });
                                                $('#content').fadeOut();  
                                                $('#clientele').fadeOut();  
                                                var client = $(this).attr("id");
                                                var defaultpage = client;
                                                $("#pagepermalink").attr("href", "http://www.leomancinidesign.com/client:" + client);
                                                $.preloadImages("images/clientele/" + client + "_website_big.png", "images/clientele/" + client + "_website.png", "images/clientele/" + client + "_logo.png", "images/clientele/" + client + ".png");
                                                $.get("content/purple.php?client=" + client + "&defaultpage=" + defaultpage, function(data){
                                                    $('#content').fadeOut();
                                                    $('#clientele').fadeOut();                                  
                                                    $('#clientele').empty().html(data);  
                                                    $('#content').fadeIn();
                                                    $('#clientele').fadeIn();
                                                });
                                                $.get("content/sidebar/clientinfo.php?client=" + client, function(data){
                                                    $('#sidebar').empty().html(data);
                                                    $(".secondclientclick").click(function() {
                                                        var defaultpage = client;
                                                        var client = $(this).attr("id");
                                                        $.get("content/purple.php?client=" + client, function(data){
                                                            $('#content').fadeOut();
                                                            $('#clientele').fadeOut();  
                                                            $(this).delay(500,function(){
                                                                $('#clientele').empty().html(data);     
                                                                $('#clientele').fadeIn();  
                                                                $('#content').fadeIn();  
                                                            });
                                                        });
                                                    });
                                                });
                                            });
                            });
                        });      
                    });
                });
                    $(this).delay(700,function() {
                    $('#content').empty().html(data);     
                    $('#content').fadeIn();  
                    $("a.fancybox").fancybox({
                        'overlayOpacity': '0.8',
                        'imageScale': false,
                        'centerOnScroll': false
                    });
                    $("#shootemail1").click(function(){
                        $("#shootemail1").animate({marginLeft:'-157px'},'slow');		
                        $("#shootemail1").css("opacity", "0.57");
                        $("#shootemail2").css("opacity", "0.0");
                        $(this).delay(500,function() {
                            $("#shootemail4").show();	
                            $("#shootemail5").show();	
                            $("#shootemail3").hide();	
                        });
                    });
                });
            });
        });
        $("#title").attr("class", "");
	});			

	// — — — — — — — — — — — —  END BUTTON PURPLE — — — — — — — — — — — 
	
	// — — — — — — — — — — — —  BEGIN BUTTON RED — — — — — — — — — — — — 	
    $("#button_red").click(function(){    
        $('#comments').hide();  
        $("#pagepermalink").attr("href", "http://www.leomancinidesign.com/art");
        var defaultpage = $("#title").attr("class");
        $('#content').fadeOut();  
        $('#clientele').fadeOut("slow");        
		$("#right").animate({marginLeft:'-251px'},'slow');		
                $("#button_blue").removeClass("selected");
                $("#button_purple").removeClass("selected");
                $("#button_red").addClass("selected");
                $("#button_green").removeClass("selected");
                $(this).delay(600,function(){
                    $("#content").removeClass("blue").removeClass("purple").addClass("red").removeClass("green");
                    $("#sidebar").removeClass("blue").removeClass("purple").addClass("red").removeClass("green");
                });
        $(this).delay(1800,function(){
            $("#right").animate({marginLeft:'0px'},'slow');	
        });	        
        $.get("content/red.php?page=" + defaultpage, function(data){
            $(this).delay(500,function(){
                $.get("content/sidebar/red.php", function(data){
                    $('#sidebar').empty().html(data);
                    $('#commentbox').ajaxForm(function() { 
                        alert("Thank you!"); 
                        $("#comment").attr('value', '').focus().blur();
                    }); 
                });                 
                if(defaultpage == "red") { defaultpage = "design"; } 
                if(defaultpage == "") { defaultpage = "design"; } 
                if(defaultpage == "none") { defaultpage = "design"; } 
                if(defaultpage == "BLOGHOME") { defaultpage = "design"; } 
                $.get("content/additional/art.php?section=" + defaultpage, function(section_content) {
                    $('#section_content').empty().html(section_content);
                    $(".red_highlight").cyclicFade({
                        repeat: 0,
                        params: [
                            {fadeout:1000, stayout:100, opout:0, fadein:1000, stayin:100, opin:1.0},
                        ]
                    });
                    // on default page load
                    $("a.fancybox").fancybox({
                        'overlayOpacity': '0.8',
                        'imageScale': false,
                        'centerOnScroll': false
                    });
                        // scroller code
                        $("#slider_" + defaultpage).easySlider({
                            continuous: true,
                            prevText: '<span class="prev">more</span><img src="images/icons/blank.png">',
                            nextText: '<span class="next">more</span><img src="images/icons/blank.png">',
                            prevId: "sliderprev",
                            nextId: "slidernext",
                            auto : true,
                            pause: 2000
                        });

                    
                });
                $('#content').empty().html(data).hide();                 
                $('#content').fadeIn();  
                $(".red_button").click(function(){    
                    $(this).addClass("red_button_selected").removeClass("red_button");  
                    $(".red_button").not(this).removeClass("red_button_selected");      
                    $(".red_button_selected").not(this).removeClass("red_button_selected").addClass("red_button");                   
                    var section = $(this).attr("id");
                    $("#pagepermalink").attr("href", "http://www.leomancinidesign.com/art:" + section);
                    $.get("content/additional/art.php?section=" + section, function(section_content){
                        $('#section_content').empty().html(section_content);        
                        $("a.fancybox").fancybox({
                            'overlayOpacity': '0.8',
                            'imageScale': false,
                            'centerOnScroll': false
                        });
                        //scroller code                        
                        $("#slider_" + section).easySlider({
                            continuous: true,
                            prevText: '<span class="prev">more</span><img src="images/icons/blank.png">',
                            nextText: '<span class="next">more</span><img src="images/icons/blank.png">',
                            prevId: "sliderprev",
                            nextId: "slidernext",
                            auto: true, 
                            pause: 2000
                        });
                    });
                });
                $(".red_button_selected").click(function(){    
                    $(this).addClass("red_button_selected").removeClass("red_button");  
                    $(".red_button").not(this).removeClass("red_button_selected");              
                    $(".red_button_selected").not(this).removeClass("red_button_selected").addClass("red_button");        
                    var section = $(this).attr("id");
                    $.get("content/additional/art.php?section=" + section, function(section_content){
                        $('#section_content').empty().html(section_content);       
                        $("a").fancybox({
                            'overlayOpacity': '0.8',
                            'imageScale': false,
                            'centerOnScroll': false
                        });       
                                       
                        //scroller code                        
                        $("#slider_" + section).easySlider({
                            continuous: true,
                            prevText: '<span class="prev">more</span><img src="images/icons/blank.png">',
                            nextText: '<span class="next">more</span><img src="images/icons/blank.png">',
                            prevId: "sliderprev",
                            nextId: "slidernext"
                        });
                    });
                });
            });
        });
        $("#title").attr("class", "");
	});				

	// — — — — — — — — — — — —  END BUTTON RED — — — — — — — — — — — — — 	
	// — — — — — — — — — — — —  BEGIN BUTTON GREEN — — — — — — — — — — — 
	
    $("#button_green").click(function(){
        $('#comments').hide();  
        $("#pagepermalink").attr("href", "http://www.leomancinidesign.com/about");
        $('#content').fadeOut();  
        $('#clientele').fadeOut("slow");  
		$("#right").animate({marginLeft:'-251px'},'slow');		
        $("#button_blue").removeClass("selected");
        $("#button_purple").removeClass("selected");
        $("#button_red").removeClass("selected");
        $("#button_green").addClass("selected");
        $(this).delay(600,function(){
            $("#content").removeClass("blue").removeClass("purple").removeClass("red").addClass("green");
            $("#sidebar").removeClass("blue").removeClass("purple").removeClass("red").addClass("green");
        });
        $(this).delay(1800,function(){
            $("#right").animate({marginLeft:'0px'},'slow');	
        });
        $.get("content/green.php", function(data){
            $(this).delay(500,function(){
                $.get("content/sidebar/green.php", function(data){
                    $('#sidebar').empty().html(data);
                });
                $('#content').empty().html(data).hide();     
                $(".get_randomfacts").click(function(){
                    $.get("content/additional/green_helper.php", function(data1){
                        $('#randomfacts1').empty().html(data1);
                    });
                    $.get("content/additional/green_helper.php", function(data2){
                        $('#randomfacts2').empty().html(data2);
                    });
                    $.get("content/additional/green_helper.php", function(data3){
                        $('#randomfacts3').empty().html(data3);
                    });
                });
                $('.get_randomfacts').click();
                $('#content').fadeIn();  
            });
        });	
        $("#title").attr("class", "");
	});		
    
	// — — — — — — — — — — — —  END BUTTON GREEN — — — — — — — — — — — — 
	
});