/*

NVda

GLOBAL JavaScript
Version 1.0alpha

*/


$(document).ready(function() {
	
	// GLOBAL
	
	// t is for main menu timer, s for switcher
		var t;
		var s;
		
	// pause plug-in
	
		(function($) {
			$.fn.extend({
				pause: function(milli,type) {
					milli = milli || 1000;
					type = type || "fx";
					return this.queue(type,function(){
						var self = this;
						setTimeout(function(){
							$(self).dequeue();
						},milli);
					});
				},
				clearQueue: function(type) {
					return this.each(function(){
						type = type || "fx";
						if(this.queue && this.queue[type]) {
							this.queue[type].length = 0;
						}
					});
				},
				unpause: $.fn.clearQueue
			});
		})(jQuery);
	
	// color switcher
	
		expand_switcher = function() {
			$("#switcher").fadeIn();
		}
		
		collapse_switcher = function() {
			$("#switcher").fadeOut("fast");
		}
	
		$("#header h1, #switcher").hover(
			function () {
				clearTimeout(s);
				expand_switcher();
			}, 
			function () {
				s = setTimeout("collapse_switcher();", 600);
			}
		);
	
		$("#trigger_green").click(function () {
			$("#header").stop().animate({backgroundPosition: '(-1800px 0)'}, {duration:1250});
			$("#download a, #content a, #content h2, #content h3, #wrapper.project #project_info p span, .post p span").css('color', '#86A83E');
			$.cookie('bgstyle', null); // delete cookie
			$.cookie('bgstyle', 'green', { path: '/' });
		});
		
		$("#trigger_blue").click(function () {
			$("#header").stop().animate({backgroundPosition: '(0 0)'}, {duration:1250});
			$("#download a, #content a, #content h2, #content h3, #wrapper.project #project_info p span, .post p span").css('color', '#238EC1');
			$.cookie('bgstyle', null); // delete cookie
			$.cookie('bgstyle', 'blue', { path: '/' });
		});
		
		$("#trigger_orange").click(function () {
			$("#header").stop().animate({backgroundPosition: '(-3600px 0)'}, {duration:1250});
			$("#download a, #content a, #content h2, #content h3, #wrapper.project #project_info p span, .post p span").css('color', '#EA8B15');
			$.cookie('bgstyle', null); // delete cookie
			$.cookie('bgstyle', 'orange', { path: '/' });
		});

	jQuery.easing.def = 'easeInOutQuart';
	
	// main menu functions
		expand_main_navigation = function() {
			$("#navgiation_breadcrumb").hide();
			$("#navigation_main").slideDown({ duration: 600 });
		}

		collapse_main_navigation = function() {
			$("#navigation_main").slideUp();
			$("#navgiation_breadcrumb").pause(300).fadeIn();
			$("#navigation_projects").slideUp();
			$("#navgiation_breadcrumb_sub").pause(300).fadeIn();
		}
		
	// project menu functions
		expand_proj_navigation = function() {
			$("#wrap_navigation_projects").show();
			$("#navgiation_breadcrumb_sub").hide();
			$("#navigation_projects").slideDown({ duration: 700 });
		}

		collapse_proj_navigation = function() {
			collapse_main_navigation();
			// $("#wrap_navigation_projects").hide();
			// $("#navgiation_breadcrumb_sub").pause(300).fadeIn();
			// $("#navigation_projects").slideUp();	
		}
					  
	// menu actions
		
		$("#wrap_navigation_main").hover(
			function () {
				clearTimeout(t);
				expand_main_navigation();
			}, 
			function () {
				t = setTimeout("collapse_main_navigation();", 600);
			}
		);
	
		$("#projects a").click(function () {
			clearTimeout(t);
			expand_proj_navigation();
			return false;
		});
		
		$("#wrap_navigation_projects").hover(
			function () {
				clearTimeout(t);
				expand_proj_navigation();
			}, 
			function () {
				t = setTimeout('collapse_main_navigation();', 600);
			}
		);
		
	// INDEX
		// index page prep
		$("#navgiation_breadcrumb").show();
		$("#navigation_main").hide();
		$("#navigation_projects").hide();
		
	// PROJECTS
		$("#close").click(function () {
			$("#project_info").fadeOut();
			$("#read_details").fadeIn();
			return false;
		});
		
		$("#read_details").click(function () {
			$("#project_info").fadeIn();
			$("#read_details").fadeOut();
			sIFR.replace(yourtypeface, {
				selector: '#project_info h3',
				css: [
			    '.sIFR-root { font-size: 20px; font-weight: normal; color: #666666; }'
			    ],
				wmode: 'transparent'
			});
			return false;
		});
		
		$("#trigger_1").click(function () {
			$(".current").hide();
			$("#navigation_images li a").removeClass("current_trigger");
			$("#background_1").fadeIn()
				.addClass("current");
			$(this).addClass("current_trigger");
			return false;
		});
		
		$("#trigger_2").click(function () {
			$(".current").hide();
			$("#navigation_images li a").removeClass("current_trigger");
			$("#background_2").fadeIn()
				.addClass("current");
			$(this).addClass("current_trigger");
			return false;
		});
		
		$("#trigger_3").click(function () {
			$(".current").hide();
			$("#navigation_images li a").removeClass("current_trigger");
			$("#background_3").fadeIn()
				.addClass("current");
			$(this).addClass("current_trigger");
			return false;
		});
		
		$("#trigger_4").click(function () {
			$(".current").hide();
			$("#navigation_images li a").removeClass("current_trigger");
			$("#background_4").fadeIn()
				.addClass("current");
			$(this).addClass("current_trigger");
			return false;
		});
		
		$("#trigger_5").click(function () {
			$(".current").hide();
			$("#navigation_images li a").removeClass("current_trigger");
			$("#background_5").fadeIn()
				.addClass("current");
			$(this).addClass("current_trigger");
			return false;
		});

});