$(document).ready(function(){
	
	$('#contact-page form input, #contact-page form textarea').each(function(){
		if($(this).attr('type')!='submit' && $(this).attr('type')!='password' ){
		
			$('label[for="'+$(this).attr('id')+'"]').css({'visibility':'hidden', 'fontSize':'85%','color':'#888'});
				
			 if ($(this).val() == '') {
				$(this).val($('label[for="'+$(this).attr('id')+'"]').text());	
			 }
				
			$(this).focus(function() {
				 $(this).val('');
				$('label[for="'+$(this).attr('id')+'"]').css({'visibility':'visible', 'fontSize':'85%','color':'#666'});
			
			});
				
			$(this).blur(function() {
				if ($(this).val() == '') {
					$(this).val($('label[for="'+$(this).attr('id')+'"]').text());	
					$('label[for="'+$(this).attr('id')+'"]').css({'visibility':'hidden', 'fontSize':'85%','color':'#888'});		
				}
			});
	
			$(this).change(function() {		
					$('label[for="'+$(this).attr('id')+'"]').css({'visibility':'hidden', 'fontSize':'85%','color':'#888'});	
			});
		}
	});

	
	// NAVIGATION
		$('#nav div.has_sub').hoverIntent(
			// mouse over
			function(){
				// find the corresponding submenu and animate it open
				$('.sub_menu', $(this)).slideDown('fast', function(){ $(this).addClass('bottom_round_10') });
			},
			// mouse out
			function(){
			// find the corresponding submenu and animate it closed
				$('.sub_menu', $(this)).fadeOut('fast', function(){ $(this).removeClass('bottom_round_10') });
			}
		);
		
		// HDR FUNCTIONS
		$('#hdr_functions > a').hoverIntent(
			// mouse over
			function(){
				$('#hdr_functions div').hide();
				$('#hdr_functions a').removeClass('current');
				$(this).addClass('current');
				
				$('#'+$(this).attr('id')+'_frm').slideDown().mouseleave(function(){
					$(this).slideUp();
					$('#hdr_functions a').removeClass('current');
				});
			},
			// mouse out
				function(){
				}
		); 
	
	

	//set class for links to external sites and other document types
	$('#content a[href^="http://"]').addClass('external').attr('target', '_blank');
	$('#content a[href^="https://"]').addClass('external').attr('target', '_blank');
	$('#content a[href^="http://scheidelpools"]').removeClass('external').attr('target', '_self');
	$('#content a[href$=".pdf"]').addClass('pdf').attr('target','_blank');
	$('#content a[href$=".ppt"]').addClass('powerpoint').attr('target','_blank');
	$('#content a[href$=".doc"]').addClass('word').attr('target','_blank');
	$('#content a[href$=".xls"]').addClass('excel').attr('target','_blank');
	$('#content a[href$=".csv"]').addClass('excel').attr('target','_blank');
	$('#content a.remove_external').removeClass('external').attr('target', '_blank');

	
	 // ROUNDED IMAGES
	// any image that has a class roundborder
	$('img.roundborder').each(function(){
		$div = $('<div/>').addClass('rounded_image round_10').css('background',"url('"+$(this).attr('src')+"') no-repeat");
		$(this).wrap($div);
		
	}); 

	
	// HIDE-SHOW 
	$('.view_details').click(	
		function(){
		console.log($(this).attr('rel'));
		var eDiv = $('div.'+$(this).attr('rel'));		
			if(eDiv.is(':hidden')){
					eDiv.show('slow');
				}								
			else if(eDiv.is(':visible')){
					eDiv.hide('slow');
				}
	
			 $(this).blur();
			return false;				
	});
	

$.ajaxSetup ({  
        cache: false  
    });  


$("#load-holder").load('ajax_pkg.php #elite');		

$('.view_pkg').click(	
		function(){	
			var ajax_load = "<img class='loading' src='img/load.gif' alt='loading...' />";
			var id =$(this).attr('rel');
			var loadUrl = 'ajax_pkg.php'

			$("#load-holder")
			.html(ajax_load)
			.load(loadUrl + " #" + id);		
		
			$(this).blur();
		
		return false;				
	});


 

$('.gsc-control').css({width:'800px'}); 

$('#search-submit').hover(
	function(){
		$(this).css({'cursor':'pointer'});
	},
	function(){
		$(this).css({'cursor':'default'});
	}
);



	// DIALOG LINKS
	$('a.dialog').click(function(){
		// do a dialog for the video embed
		makeDialog('<h3><img src="layout_imgs/loading_bar.gif" alt="loading" /> Loading '+$(this).attr('title')+'</h3><p>please wait</p>', $(this).attr('title'));
		var element_rel = $(this).attr('name');
		// ajax in the data
		$('#made_dialog').load($(this).attr('href')+(element_rel ? ' '+element_rel : ''), function(rsp){
			// animate the containers to show everything
			$(this).parent().css('width','705px').animate( {
				top: $(this).parent().offset().top - (screen.height/4) + 20,
				left: '50%',
				marginLeft: -($(this).width() / 2)
			}, 'fast');
		});

		return false;
	});

	







/* PAGINATION PODCAST PAGE */
	
	//how many items to show (2 rows of items bars each has 3 floated podcast items)
	var show_per_page = 3;
	
	//get number of item bars
	var number_of_items = $('.item_bar').size();
	
	//calculate the number of pages we are going to have
	var number_of_pages = Math.ceil(number_of_items/show_per_page);
	
	//set the value of our hidden input fields which store the page numbers
	$('#current_page').val(0);
	$('#show_per_page').val(show_per_page);
	
	var navigation_html = '';
	var current_link = 0;
	
	navigation_html += '<a class="previous_link" href="javascript:previous();">Prev<\/a>';
	
	while(number_of_pages > current_link){
		navigation_html += '<a class="page_link" href="javascript:go_to_page(' + current_link +')" longdesc="' + current_link +'">'+ (current_link + 1) +'<\/a>';
		current_link++;
	}
	
	navigation_html += '<a class="next_link" href="javascript:next();">Next<\/a>';
	
	$('#pagination').html(navigation_html);
	
	//add active_page class to the first page link
	$('#pagination .page_link:first').addClass('active_page');
	
	//hide all the elements inside content div
	$('.item_bar').css('display', 'none');
	
	//and show the first n (show_per_page) elements
	$('.item_bar').slice(0, show_per_page).css('display', 'block');
	$('.page_link, .previous_link, .next_link').click(function(){
		$(this).blur();
	});
	
	/* hide prev link on page load */
	$('.previous_link').css({'color' : '#F5EFE1', 'borderColor' : '#F5EFE1'});
	$('.previous_link').hover(function(){
		$(this).css({'cursor' : 'default'});
	}); 







}); // end document ready






/* POOL DESIGNS PAGINATION FUNCTIONS */
function previous(){
	new_page = parseInt($('#current_page').val()) - 1;
	
	//if there is an item before the current active link run the function
	if($('.active_page').prev('.page_link').length==true){
		go_to_page(new_page);
	}
}



function next(){
	new_page = parseInt($('#current_page').val()) + 1;
//if there is an item after the current active link run the function
	
	if($('.active_page').next('.page_link').length==true){
		go_to_page(new_page);
	}
}

function go_to_page(page_num, number_of_pages){
	//get the number of items shown per page
	var show_per_page = parseInt($('#show_per_page').val());
	
	//get the element number where to start the slice from
	start_from = page_num * show_per_page;
	
	//get the element number where to end the slice
	end_on = start_from + show_per_page;
	
	//hide all children elements of pagination-wrapper div, get specific items and show them
	$('.item_bar').css('display', 'none').slice(start_from, end_on).fadeIn(3000);
	
	/*get the page link that has longdesc attribute of the current page and add active_page class to it
	and remove that class from previously active page link*/
	$('.page_link[longdesc=' + page_num +']').addClass('active_page').siblings('.active_page').removeClass('active_page');
	
	//update the current page input field
	$('#current_page').val(page_num);
	
	/* HIDE PREV and NEXT */
	if($('.active_page').text()==1){
		$('.previous_link').css({'color' : '#F5EFE1', 'borderColor' : '#F5EFE1'});
		$('.previous_link').hover(
			function(){
				$(this).css({'cursor' : 'default'});
				$('.previous_link').css({'color' : '#F5EFE1', 'borderColor' : '#F5EFE1'});
			}
		);
	
	}else{
		$('.previous_link').css({'color' : '#000', 'borderColor' : '#C2B592'});
		$('.previous_link').hover(
			function(){
				$(this).css({'cursor' : 'pointer', 'color' : '#888', 'borderColor' : '#C2B592'});
				},
				function(){
				$(this).css({'cursor' : 'default', 'color' : '#000', 'borderColor' : '#C2B592'});
				}
			);
	}
	
	if( $('.active_page').next('.next_link').length==true){
		$('.next_link').css({'color' : '#F5EFE1', 'borderColor' : '#F5EFE1'});
		$('.next_link').hover(
			function(){
				$(this).css({'cursor' : 'default'});
				$('.next_link').css({'color' : '#F5EFE1', 'borderColor' : '#F5EFE1'});
			});
	}else{
		$('.next_link').css({'color' : '#000', 'borderColor' : '#C2B592'});
		$('.next_link').hover(
			function(){
				$(this).css({'cursor' : 'pointer', 'color' : '#888', 'borderColor' : '#C2B592'});
			},
			function(){
				$(this).css({'cursor' : 'default', 'color' : '#000', 'borderColor' : '#C2B592'});
			}
		);
	}



// keeps the pagination in same place
$(window).scrollTop($('a#top').position().top) ; 

}






function makeGoogleMap(address){
	var base = "http://maps.google.com/maps?f=q&hl=en&geocode=&time=&date=&ttype=&q=";
	return base + escape(address);
}


function makeDialog(text, dialog_title, buttons, width, height, hideTitleBar){
	if(!buttons){
		buttons = {
			Ok: function() {
				$(this).dialog('close');
			}
		}
	}

	$('<div id="made_dialog">'+text+'</div>').dialog({
		title: dialog_title,
		dialogClass: hideTitleBar ? 'hide_title' : 'alert',
		bgiframe: true,
		modal: true,
		stack:true,
		autoOpen:true,
		width: width ? width : 460,
		minHeight: height ? height : 220,
		draggable: true,
		resizable: true,
		buttons: buttons,
		close: function(event, ui){
			$(this).remove();
		}
	});
}

window.alert = function(txt){
	makeDialog(txt, 'The page said:');
}

//CATCH CONSOLE.LOG FOR NO-FIREBUG
if (typeof console == 'undefined' || typeof console.log == 'undefined') { console = { log : function (text) { return false; } } }


