var contact_pos = 0;
var login_pos 	= 0;
// what version of flash is needed;
var fla_needed = 9;

$(document).ready(function() {
	
	/**
	 * if not FF2 on mac load flash nav else load the html navigation
	 * Only load sIFR if not FF2 on mac
	 */

	if((navigator.appVersion.indexOf("Mac") != -1) && ($.browser.name == 'firefox') && ($.browser.version.substr(0,1) == "2")) {
		$('#nav').load('./inc/ff2_nav.inc.php');
		$('h3').css({'height' : '28px'});
	} else {
		$('#nav').html('<a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a>');
		// loadFlash located in header (so flash vars will work)
		loadFlash();

	}
	
	var add1 = '<a href="mailt';
	var add2 = 'o:info@uni';
	var add3 = 'tonenine.c';
	var add4 = 'om">';
	$('#email').html(add1 + add2 + add3 + add4 + 'info@UnitOneNine.com</a>');
	
	
	/**
	 * SHOW / HIDE LOGIN
	 */
	$('#login').click(function() {
		if(login_pos == 0) {
			$('#login_form').slideDown('fast');	
			login_pos = 1;		
		} else {
			$('#login_form').slideUp('fast');	
			login_pos = 0;
		}

	});
	
	/**
	 * clear field on focus
	 */
	var tmp_val;
	$('input, textarea').focus(function() {
		tmp_val = $(this).val();
		$(this).val('');
	});
	$('input, textarea').blur(function() {
		if($(this).val() == '') {
			$(this).val(tmp_val);
		}
	})
	
	
	/**
	 * SHOW / HIDE FOOTER
	 */
	$("#contact_btn").click(function(){
		if($.browser.name == 'msie' && $.browser.version <= 6 ) {
			/**
			 * if IE6
			 */
			if(contact_pos == 0) {
				$("#contact_footer").css({overflow: 'visible'});
				window.scrollBy(0, $('#wrapper').height());
				//$('#contact_img').attr({src: './img/contact_up.png'});
				contact_pos = 1;
			} else if(contact_pos == 1) {
				$("#contact_footer").css({bottom: '0px', height: '50', overflow: 'hidden'});
				//$('#contact_img').attr({src: './img/contact_down.png'});
				contact_pos = 0;
			}
		} else {
			/**
			 * All other browsers
			 */
			if(contact_pos == 0) {
				$("#contact_footer").css({bottom: '350px'});
				//$(this).animate({top: '-=385px'}, "slow");
				$('#contact_img').attr({src: './img/contact_up.png'});
				contact_pos = 1;
			} else if(contact_pos == 1) {
				//$(this).animate({top: windowHeight() - 37 + 'px'}, "slow");
				$("#contact_footer").css({bottom: '0px'});
				$('#contact_img').attr({src: './img/contact_down.png'});
				contact_pos = 0;
			}
		}
	});
	
	/**
	 * sub-navigation
	 */	
	$('#all').click(function() {
		$('.current_nav').removeClass('current_nav');
		$(this).addClass('current_nav');
		$('#list_projects').load('./scripts/get_project_list.php', {show_this: 'all'});
		$('.Brand').fadeTo('slow', 1);
		$('.Web').fadeTo('slow', 1);
		$('.Print').fadeTo('slow', 1);
	});
	$('#print').click(function() {
		$('.current_nav').removeClass('current_nav');
		$(this).addClass('current_nav');
		$('#list_projects').load('./scripts/get_project_list.php', {show_this: 'Print'});
		$('.Brand').fadeTo('slow', .3);
		$('.Web').fadeTo('slow', .3);
		$('.Print').fadeTo('slow', 1);
	});
	$('#web').click(function() {
		$('.current_nav').removeClass('current_nav');
		$(this).addClass('current_nav');
		$('#list_projects').load('./scripts/get_project_list.php', {show_this: 'Web'});
		$('.Brand').fadeTo('slow', .3);
		$('.Web').fadeTo('slow', 1);
		$('.Print').fadeTo('slow', .3);
	});
	$('#brand').click(function() {
		$('.current_nav').removeClass('current_nav');
		$(this).addClass('current_nav');
		$('#list_projects').load('./scripts/get_project_list.php', {show_this: 'Brand'});
		$('.Brand').fadeTo('slow', 1);
		$('.Web').fadeTo('slow', .3);
		$('.Print').fadeTo('slow', .3);
	});
	
	/**
	 * contact form
	 */	
	$('#send').click(function() {
		var errors = '';
		$('#results').hide();		
		if(($('#name').val() == 'NAME') || ($('#name').val() == '')) {
			errors += '* The Name Field is Required.\n';
		}
		if(($('#contact_form #email').val() == 'EMAIL') || ($('#contact_form #email').val() == '')) {
			errors += '* The Email Field is Required.\n';
		}
		if(($('#contact_form #phone').val() == 'PHONE') || ($('#contact_form #phone').val() == '')) {
			errors += '* The Phone Number Field is Required.\n';
		}
		if(($('#msg').val() == 'MESSAGE') || ($('#msg').val() == '')) {
			errors += '* You Must Type a Message.\n';
		}
		if(errors != '') {
			alert(errors);
			errors = null;
		} else {
			var n = $('#name').val();
			var e = $('#contact_form #email').val();
			var p = $('#contact_form #phone').val();
			var m = $('#msg').val();
			
			$('#results').load('./scripts/contact.php', {name: n, email: e, phone: p, msg: m}, function() {
				$('#results').show();
			});
		}
	});
	
});

