	$(document).ready(function(){
		
	/*
		// FANCY BOX
		$("a.navView").fancybox( {
			'overlayShow'			: true,
			'hideOnContentClick'	: false,
			'centerOnScroll'		: true,
			'overlayOpacity'		: 0.6,
			'frameWidth'			: 800,
			'frameHeight'			: 560

		});*/
		
		// TWITTER
		$("#TwitterNext").mouseup( function() {
			var count = $("#TwitterSlider").css("marginLeft");
			count = count.substring(0, count.length-2);
			if (count != -9082) {
				$("#TwitterSlider").animate( {marginLeft:"-=478px"}, 500);			
			}	
		});

		$("#TwitterPrev").mouseup( function() {
			var count = $("#TwitterSlider").css("marginLeft");
			count = count.substring(0, count.length-2);
			if (count != 0) {
				$("#TwitterSlider").animate( {marginLeft:"+=478px"}, 500);
			}
		});

		// MAIN NAVIGATION - DISABLE CSS HOVER
		$(".nav").children("li").each(function() {
			$(this).children("a").css( { backgroundImage: "none"} );
		});	
		
		
		// FADE TOGGLER
		jQuery.fn.fadeToggle = function(speed, easing, callback) { 
			return this.animate({opacity: 'toggle'}, speed, easing, callback); 
		};
		
		// MAIN NAVIGATION - Attach Function
		function attachNavEvents(parent, myClass) {

			$(parent + " ." + myClass).mouseover( function() {
				$(this).append('<div class="nav-' + myClass + '"></div>');
				$("div.nav-" + myClass).css({display: "none"}).fadeIn(200);
			}).mouseout(function() {
				$("div.nav-" + myClass).fadeOut(400, function() { $(this).remove(); });
			}).mousedown(function() {
			}).mouseup(function() {
			});
		}
		
		// CONTACT FUNCTION
		function setOff(name) {
			$currentstatus = $(name).children(".boxContactStatus").text();
			if ( $currentstatus == 'ON') {
				$(name).children(".boxContactStatus").replaceWith("<span class='boxContactStatus'>OFF</span>");
				$(name).slideUp();
			} 
		}
		
		function checkAllOff() {
			//$statusTwitter = $("#boxContactTwitter").children(".boxContactStatus").text();
			//$statusFacebook = $("#boxContactFacebook").children(".boxContactStatus").text();
			//$statusEmail = $("#boxContactEmail").children(".boxContactStatus").text();
			//if ($statusTwitter == 'ON' || $statusFacebook == 'ON' || $statusEmail == 'ON') {
				//return 'NO';
			//}
		}
		function setToggle(name) {
		/*
			$currentstatus = $(name).children(".boxContactStatus").text();
			if ($currentstatus == 'ON') {			
				$(name).children(".boxContactStatus").replaceWith("<span class='boxContactStatus'>OFF</span>");
				$(name).slideUp();
				$("#contactClose").fadeTo(500, 0.0);
			} else {
				if (checkAllOff() == 'NO') {
					if (name == '#boxContactEmail') {
						setOff('#boxContactTwitter');
						setOff('#boxContactFacebook');
					} else if (name == '#boxContactTwitter') {
						setOff('#boxContactEmail');
						setOff('#boxContactFacebook');
					} else if (name == '#boxContactFacebook') {
						setOff('#boxContactTwitter');
						setOff('#boxContactEmail');
					}
					setTimeout('$("' + name + '").slideDown()', 500);							
				} else {
					$(name).slideDown();
				}
				$(name).children(".boxContactStatus").replaceWith("<span class='boxContactStatus'>ON</span>");
				$("#contactClose").fadeTo(500, 1);
			}
			*/
		}
		
		// CONTACTS INDIVIDUAL
		$(".contactEmail").mouseup( function() { setToggle("#boxContactEmail"); });
		$(".contactTwitter").mouseup( function() { setToggle("#boxContactTwitter"); });
		$(".contactFacebook").mouseup( function() { setToggle("#boxContactFacebook"); });
		$("#contactClose").mouseup( function() {
			setOff('#boxContactTwitter');
			setOff('#boxContactEmail');
			setOff('#boxContactFacebook');
			$("#contactClose").fadeTo(500, 0.0);
		});
		
		// CONTACT FORMS
		$("#contactClose").fadeTo(0, 0.0);
		$("#boxContactTwitter").hide();
		$("#boxContactEmail").hide();
		$("#boxContactFacebook").hide();
		
		// EMAIL SEND
		function sendMail() {
			$name = $("#formName").val();
			$email = $("#formEmail").val();
			$message = $("#formMessage").val();
			$.get("scripts/mail.php", {name: $name, email: $email, message: $message} );
		}

		// Email Animation
		$("#EmailProceed").mouseup( 
			function() {
				sendMail();
				$(this).parent().animate( {left: "-900px"}, 500).fadeTo(500, 0);
				
				$("#EmailStatus").animate( {left: "0px"}, 500);
				setTimeout('$("#EmailStatus").animate( {left: "-675px"}, 500)', 1800);
				setTimeout('$("#EmailComplete").animate( {left: "0px"}, 500)', 1800);
				setTimeout("setToggle('#boxContactEmail')", 1000);
			}
		);
			
		// MAIN NAVIGATION - RUN ATTACH FUNCTION
		attachNavEvents(".nav", "contactTwitter");
		attachNavEvents(".nav", "contactFacebook");
		attachNavEvents(".nav", "contactEmail");
		
		// Portfolio Navigation
		$("#boxPortfolio ul li").mouseover( function() {
			$(this).children(".portfolioNav").stop(), $(this).children(".description").stop();
			$(this).children(".description").animate( { top: "220px"}, 300),
			$(this).children(".portfolioNav").fadeTo(0, 0.9);
			//$(this).siblings(".description").fadeTo("normal", 0);
		}).mouseout( function() {
			$(this).children(".portfolioNav").stop(), $(this).children(".description").stop();
			$(this).children(".description").animate( { top: "179px"}, 300),
			$(this).children(".portfolioNav").fadeTo(0, 0);
			//$(this).siblings(".description").fadeTo("normal", .9);
		});
		
		// Portfolio Navigation fade
		$(".portfolioNav").fadeTo(0, 0);	
				
		// TEMPORARY UGLY SWITCH SOLUTION
		function updateLink(object) {
			var count = object.children("span.slider").children().size();
			var string = object.children("span.portfolioNav").children("a.navView").attr("href");
			var position = string.substring(string.length, string.length -1);
			string = string.substring(0, string.length -1);			
			if ( position >= count) {
				position = 1;
			} else {
				position++;
			}
			object.children("span.portfolioNav").children("a.navView").attr("href", string + position);	
		};
	/*
		$("#boxPortfolio ul li").each( function() {
			var imageIndex = $(this).children("span.slider").children().size();
			
			switch(imageIndex) {
			case 1:
				$(this).toggle(
			function() { $(this).children("span.slider").animate( { marginLeft:"0"}, 500) }				
				);
			break
			
			case 2:
				$(this).toggle(
			function() { $(this).children("span.slider").animate( { marginLeft:"-=296px"}, 500, updateLink($(this)) );  },
			function() { $(this).children("span.slider").animate( { marginLeft:"0"}, 500, updateLink($(this))); }				
				);
			break
			
			case 3:
				$(this).toggle(
			function() { $(this).children("span.slider").animate( { marginLeft:"-=296px"}, 500, updateLink($(this)) );  },
			function() { $(this).children("span.slider").animate( { marginLeft:"-=296px"}, 500, updateLink($(this)) );  },
			function() { $(this).children("span.slider").animate( { marginLeft:"0"}, 500, updateLink($(this)) );  }				
				);
			break

			case 4:
				$(this).toggle(
			function() { $(this).children("span.slider").animate( { marginLeft:"-=296px"}, 500, updateLink($(this)) ); },
			function() { $(this).children("span.slider").animate( { marginLeft:"-=296px"}, 500, updateLink($(this)) ); },
			function() { $(this).children("span.slider").animate( { marginLeft:"-=296px"}, 500, updateLink($(this)) ); },
			function() { $(this).children("span.slider").animate( { marginLeft:"0"}, 500, updateLink($(this)) ); }				
				);
			break

			case 5:
				$(this).toggle(
			function() { $(this).children("span.slider").animate( { marginLeft:"-=296px"}, 500, updateLink($(this)) ); },
			function() { $(this).children("span.slider").animate( { marginLeft:"-=296px"}, 500, updateLink($(this)) ); },
			function() { $(this).children("span.slider").animate( { marginLeft:"-=296px"}, 500, updateLink($(this)) ); },
			function() { $(this).children("span.slider").animate( { marginLeft:"-=296px"}, 500, updateLink($(this)) ); },
			function() { $(this).children("span.slider").animate( { marginLeft:"0"}, 500, updateLink($(this)) ); }				
				);
			break

			}
		});
*/
	
	});
	
