var Site = 
{
	onReady:	function()
	{
		//alert("onready");
		for (var selector in this.elements)
		{
			var $elms = $(selector);
			
			if ($elms.size() > 0)
			{
				this.elements[selector]($elms);
			}
		}       
       
	},
	
	

	elements:
	{		
		
			'div.gallery.course-provider-gallery div.gallery-image':function($elms){
				$("a[rel^='prettyPhoto']",$elms).prettyPhoto({
							animationSpeed: 'normal', /* fast/slow/normal */
							padding: 40, /* padding for each side of the picture */
							opacity: 0.8, /* Value betwee 0 and 1 */
							showTitle: true, /* true/false */
							allowresize: true, /* true/false */
							counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
							theme: 'light_square', /* light_rounded / dark_rounded / light_square / dark_square */
							callback: function(){}
						});
			},
			
			'#PageSearchIndexForm':function($elms){
				$('#PageKeyword',$elms).bind('click',function(){
					$('#PageKeyword',$elms).val("");
				});
				
				
			},
			
			//Start date and end date
			'form#internship-search-form':function($elms){
				
				//$('#start_period',$elms).datepick();
				//$('#end_period',$elms).datepick();
				$('#start_period',$elms).datepick({dateFormat: 'dd/mm/yy', showOn: 'button', buttonImageOnly: true, buttonImage: '/img/common/calendar.jpg'});
				$('#end_period',$elms).datepick({dateFormat: 'dd/mm/yy',showOn: 'button', buttonImageOnly: true, buttonImage: '/img/common/calendar.jpg'});
			},
			
			'div.enrolment-process':function($elms){
				
				$('#upload_anoter_file').bind('click', function(e){
					//console.log($('.enrolment_file_upload[style]'));
					var input_files = $('.enrolment_file_upload.hidden', $elms); //all in_active input files
					if (input_files.size() > 0){
						//input_files.eq(0).removeAttr('style');
						$('.enrolment_file_upload.hidden',$elms).eq(0).removeClass('hidden');
						//alert($('.enrolment_file_upload[style]',$elms).eq(0).attr('style'));
					}
					if (input_files.size()==1){
						$('#upload_anoter_file').attr('style', 'display:none');
					}
					e.stopPropagation();
					return false;
					
				});
				
				//Check on loading page
				var input_files = $('.enrolment_file_upload');
				for (i=0; i< input_files.size(); i++){
					if ((input_files.eq(i).val()!= '')){
						input_files.eq(i).removeAttr('style');
					}
				}
				
			},
	
			//	Top ads, randomly display one at a time
			'.top-ads':function($elms){
				$("ul li", $elms).hide();
				len = 1; //$(".top-ads ul li").length;
				ran = Math.floor(Math.random()*len) + 1;
				$("ul li:nth-child(" + ran + ")", $elms).show();
			},
			
			// Side ads, show two ads
			'.side-item-adverts':function($elms){
				$("li", $elms).hide();
				
				// Randomly display the first ad
				len = $("li", $elms).length;
				first = Math.floor(Math.random()*len) + 1;
				$("li:nth-child(" + first + ")", $elms).show();

				// Randomly display the second
				if (len >= 2){
					second = first;
					while(second == first){
						second = Math.floor(Math.random()*len) + 1;
					}
					$("li:nth-child(" + second + ")", $elms).show();
				}
			},
			
			// Contact us page
			'.contact-us-page':function($elms){
				
				showActivity = function(){
					$('.message').css('display', 'none');
					$('.loading').css('display', 'block');
				}
			
				hideActivity = function(){
					$('.message').css('display', 'block');
					$('.loading').css('display', 'none');					
				}
				
				bindSubmit = function(){
					$('.ajax-contact-us-form form').bind("submit", 
							function(e) {
								showActivity();
			
								var data = $(this).serializeArray();
								var action	= $(this).attr('action');
								//submit form
								$('.ajax-contact-us-form').load(
									action,
									data,
									function() {
										hideActivity();
										bindSubmit();
									}
								);
								
								e.preventDefault();
								e.stopPropagation();
								return false;
							}
						);	
					
				}
				
				bindSubmit();				
			}
			
			
		}
	}
	
	

$(document).ready(
	function()
	{
		Site.onReady();
	}
);
