$(function() {
	$("select, input:checkbox, input:radio").uniform();
	
    $('#special_offer_rotator').cycle({
		fx:     'fade',
		timeout: 4000
	});
//directory paging	
	$("#directorytable") 
    .tablesorter({widthFixed: true, widgets: ['zebra']}) 
    .tablesorterPager({container: $("#paging"),positionFixed: false });
	
	$("#eventtable") 
    .tablesorter({widthFixed: true, widgets: ['zebra']}) 
    .tablesorterPager({container: $("#paging"),positionFixed: false });
	
	
	$('.pagesize').change(function() {
	var value = $('.pagesize').val();
	$('#viewstart').html('1');
	$('#viewcount').html(value);
	});
	
	var value = $('.pagesize').val();
	var total = $('#totalcount').text();
	if(parseInt(value) >= parseInt(total)){
	$('#viewcount').html(total);
	}else{
	$('#viewcount').html(value);
	}
	
	$('.next').click(function(e){
	var value = $('.pagesize').val();
	var start = $('#viewstart').text();
	var end = $('#viewcount').text();
	var total = $('#totalcount').text();
	var newstart = parseInt(start) + parseInt(value);
	var newend = newstart + parseInt(value) - 1;
	var remaining = parseInt(total) - newend;
	if(end != parseInt(total)){
	if(remaining <= 0 && remaining < value){
	$('#viewstart').html(newstart);
	$('#viewcount').html(newend + remaining);
	}else{
	$('#viewstart').html(newstart);
	$('#viewcount').html(newend);
	}
	}
	e.preventDefault();
	});
	
	$('.prev').click(function(e){
	var value = $('.pagesize').val();
	var start = $('#viewstart').text();
	var end = $('#viewcount').text();
	var total = $('#totalcount').text();
	var newstart = parseInt(start) - parseInt(value);
	var newend = newstart + parseInt(value) - 1;
	var remaining = parseInt(total) + newend;
	if(start != 1){
	$('#viewstart').html(newstart);
	$('#viewcount').html(newend);
	}
	e.preventDefault();
	});
//directory paging end
	$('#mainnav li ul > li:last-child a').css('border-bottom','none');
	
	$('#directions').submit(function() {
	calcRoute();
	return false;
	});
	
	//$("ul li:nth-child(gt9)").hide();
	$('.photoset ul').each(function(){
		var n = $(this);
		if($(this).children('li').size() >= 10){
		n.children('li:gt(9)').hide();
		$("<a href=\"#\" class=\"more\">view more &raquo;</a>").appendTo(this).parent('.photoset');
		}
		});
		
			//var n = $(".photoset ul li").size();
		//if(n >= 10){
		//$('ul li:gt(9)').hide();
		
		//}

	
	$('.photoset').toggle(function(event) {
		var $tgt = $(event.target);
			if ($tgt.is('a.more')) {
				$('ul li:gt(9)',this).show();
				$($tgt).html('hide');
			}
			}, function(event) {
		var $tgt = $(event.target);
			if ($tgt.is('a.more')) {
				$('ul li:gt(9)',this).hide();
				$($tgt).html('view more &raquo;');
			}
			});
	
	$('a.video').click(function(event) {
		var video = $(this).attr('rel');
		//alert(video);
		$('.view').html('');
		$('.view').append("<div id=\"wrapper\"><a href=\"#\" class=\"close\">Close</a><object width=\"640\" height=\"385\"><param name=\"movie\" value=\"http://www.youtube.com/v/"+video+"?fs=1&amp;hl=en_US\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"http://www.youtube.com/v/"+video+"?fs=1&amp;hl=en_US\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"640\" height=\"385\"></embed></object></div>");
		event.preventDefault();
		$('a.close').click(function(event) {
		$(this).parent().remove();
		event.preventDefault();
	});
	});	
	
	$('a.photo').click(function(event) {
		var photo = $(this).attr('rel');
		//alert(video);
		$('.view').html('');
		$('.view').append("<div id=\"wrapper\"><a href=\"#\" class=\"close\">Close</a><img src=\""+photo+"\" /></div>");
		event.preventDefault();
		$('a.close').click(function(event) {
		$(this).parent().remove();
		event.preventDefault();
	});
	});	
	
	$('#emailsignup').ajaxForm({ 
                target: '#emailstatus', 
				success: function() { 
				$('#emailstatus').fadeIn('slow'); 
				}  
     }); 
	
	
	
	function checkForm(){
		$("#request_info").validate({
		rules: { 
		name: "required",// simple rule, converted to {required:true} 
		comment: { 
		required: true 
		}, 
		email: {// compound rule 
		required: true, 
		email: true 
		}, 
		phone: {
		required: true,
		phoneUS: true
		}
		}, 
		messages: { 
		comment: "Please enter a comment." 
		}
		});
		
		
		alert($("#request_info").valid());
	}

		$('#request_info').ajaxForm({
                target: '#form_status',
				beforeSubmit: checkForm,
				success: function() { 
				$('#form_status').fadeIn('slow'); 
				},
				resetForm: true
		});	
	
	

});

