/* * * * CUSTOM JQUERY * * * * * * * * * * * * * * * * * * * * * * * * *

Author: Jimmy (18/11/2010)
Website Reference: PLD Organisation (http://www.pld-literacy.org)
Last Update: 19/11/2010 (Jimmy)

Requirements:

	js/jquery.js
	
	Other requirements based off jQuery modules used in this file:
	
	js/jquery.lightbox.js // Used for LIGHTBOX image zooming functionality
	js/jquery-ui.js // Used for Datepicker (form element)

Purpose:

	This code allows all the website's jQuery to be stored in a single
	location for easy code changes. All code should use listeners and
	callback functions for easy control in once place.
	
	Standard modules should be launched from here (lightbox, cufon, etc.)
	for easy site-wide management.
	
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */


$(document).ready(function(){

	// Launch LIGHTBOX image zoom on any link with lightbox class
	// Link MUST point to an image otherwise you will get funny results.
	
	$('a.lightbox').lightBox(); 
	
	// Launch CYCLCE jQUERY module to rotate the images
	
	$('.slideshow').cycle({ speed: '2000', pager:  '#homepage_slides_nav',  pagerAnchorBuilder: function(index, el) { return '<a href="#"> </a>'; }});
		
	/* * * * SUBMENU * * * */ 

	// PURPOSE: This code is used with the SUBMENU module (includes/submenu.js)
	// to manipulate the view of the menu levels with sliders, etc.
	
 	// Hide SUBMENU Secondary level if JavaScript is active 
	// (show for non-JS capable browsers)
	
 	$('ul.submenu_links_secondary:not(.current)').hide();
 	
 	if($('ul.submenu_links_secondary.current').length == 0) {
 		$('ul.submenu_links_secondary:first').show();
 	}

	$('form#product_search').submit(function() {
	
		if($(this) + ' #search_field'.val() == "Enter search criteria") {
			alert('You must enter a search critera');
			return false;
		}
	
	});

 	// If the user CLICKS on a parent link in the submenu
 	// Slide down the secondary level list
 	// NOTE: The .not will exclude all CHILD links (in the secondary level) from sliding
 	
 	$('ul#submenu_links.resources_submenu li a').not('ul.submenu_links_secondary li a').click(function() {

		// If you click the one that is ALREADY open then don't do anything
 		if($(this).next().is(':hidden')) {
		 	$('ul.submenu_links_secondary').slideUp(300);
			$(this).next('ul.submenu_links_secondary').slideToggle(300);
 		}

		return false
		
	});
	
	// Only display other country, if required
	$('#shipping_country').change(function() {
		if($('#shipping_country').val() == "2") {
			$('#shipping_state_tr').slideUp(300);
			$('#shipping_state').val(10);
			$('#country_tr').slideDown(300);
			$('#region_tr').slideDown(300);
		} else {
			$('#shipping_state_tr').slideDown(300);
			$('#shipping_state').val(8);
			$('#country_tr').slideUp(300);
			$('#region_tr').slideUp(300);
		}
		
	});	

	// Shoot off an email to the administration that a "Pending Paypal" order has been made
	$("#paypal_submit").click(function() {
		$.ajax({ url: 'https://www.pld-literacy.org/includes/paypal_pending.php', async: false, data: 'order_id='+$('#invoice').val() }); 
		return true;
	});
		
	// Launch UNIFORM jQUERY module to skin the SELECT form elements
	$("#image_id").uniform(); 
 
});

