﻿﻿$(document).ready(function(){


	if (navigator.platform.search('Mac') != -1 && navigator.appVersion.search('Safari') != -1) {
		$('#all_employees').css('margin-left', '-1px');
		$('#top_li').css('padding-bottom', '5px');
	}
	
	var image_field;
	
	$('#s').clearField();
	
	$('#comment_form input').clearField();
	
	var url = document.location.href;
	if (url.search('#comment') != -1) {
		$('#comment_message').css('visibility', 'visible')
	}
	
	$('#commentform').submit(function() {
		var error = false;
		var patt = /(\w[-._\w]*\w@\w[-._\w]*\w\.\w{2,3})/;
		
		var comment = $('#comment').val();
		var author = $('#author').val();
		var email = $('#email').val();
		
		if (jQuery.trim(comment) == '') {
			$('#comment').addClass('error');
			error = true;
		} else {
			$('#comment').removeClass('error');
		}
		
		if (jQuery.trim(author) == '' || (author == $('#author').attr('rel'))) {
			$('#author').addClass('error');
			error = true;
		} else {
			$('#author').removeClass('error');
		}
		
		if (!patt.test(email)) {
			$('#email').addClass('error');
			error = true;
		} else {
			$('#email').removeClass('error');
		}
		
		if (!error) {
			return true;
		} else {
			return false;
		}
		
	});	
	
	$('#post_images li').live('click', function() {
		$(this).addClass('hidden');
		if (String($(this).next('li').html()) != 'null') {
			$(this).next('li').removeClass('hidden');
		} else {
			$('#post_images li:first').removeClass('hidden');
		}
	});
	
	$('#prev_img').live('click', function() {
		var image = $(this).parent().find('li:not(.hidden)');

		if (String(image.prev('li').html()) != 'null') {
			$(this).parent().find('li').each(function () {
				$(this).addClass('hidden');
			});
			
			image.prev('li').removeClass('hidden');
		} else {
			$(this).parent().find('li').each(function () {
				$(this).addClass('hidden');
			});	
			
			$('#post_images li:last').removeClass('hidden');
		}
	});
	
	$('#next_img').live('click', function() {
		var image = $(this).parent().find('li:not(.hidden)');
		
		if (String(image.next('li').html()) != 'null') {
			$(this).parent().find('li').each(function () {
				$(this).addClass('hidden');
			});
			
			image.next('li').removeClass('hidden');
		} else {
			$(this).parent().find('li').each(function () {
				$(this).addClass('hidden');
			});	
			
			$('#post_images li:first').removeClass('hidden');
		}
	});
	
	$('.category_list li').click( function() {
		
		if ($(this).find('.category').is(':checked')) {
			$(this).find('.category').attr('checked', false);
		} else {
			$(this).find('.category').attr('checked', true);
		}
		
		$(this).parent().parent().submit();
		/*
		 * 
		 * 
		 * 
		 * 
		 * 
		 * 
		 */
		//$('#category_form').submit();
	});
	
	/*$('.share_f').click( function() {
		
		var url = 'http://www.facebook.com/sharer.php?u='+$(this).attr('href');
		window.open(url,'','scrollbars=no,menubar=no,height=500,width=600,resizable=no,toolbar=no,location=no,status=no');
		return false;
	});*/
	
	
	$('.category:checked').each(function () {
		$(this).next('label').addClass('active');
	});
	
	$('.menu li:not(:.active)').hover(
		function () {
			$(this).css('background-color', '#F9F9F9');
		}, 
		function () {
			$(this).css('background-color', '#ffffff');
		}
	);
	
	$('#post_images span').hover(
			function () {
				$(this).css('background-position', '0 -40px');
			}, 
			function () {
				$(this).css('background-position', '0 0');
			}
		);
	
});

function submitform() {
	document.category_form.submit();
}

