 $(document).ready(function(){
		// Language Dropdown 
		
		jQuery('#ChangeLanguage a').click(function(){
			jQuery(this).next('ul').slideToggle('fast');
			return false;
		}
		);
		
		// Input Field Focus
	
		jQuery('ul#nav li.searchForm input[type="text"], .newsletterSignup input[type="text"]').each(function(){
		jQuery(this).focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
		}).blur(function() {
			if( !this.value.length ) {
				this.value = this.defaultValue;
			}
		});
		});
		
		//Initialize Ajax Tabs
        jQuery('#ArticleBody > ul#AjaxTabs').tabs();

		// CheckBox and Radio button Replacement : http://www.protofunc.com/scripts/jquery/checkbox-radiobutton/
		
		jQuery('input[type=checkbox]')
			.checkBox()
			.bind('checkBoxchange', function(e,ui){
				
				jQuery('#HighlightItem .resultsRecommend dl').each(function(i){
				
					
				});
			});
		
		jQuery('dl.teasers input, .optionSelect input[type=radio]').checkBox();
		
		// CheckAll 
		
		$('.optionEverything input, #ShowAll').toggle(function(){ 
			$('input[type=checkbox]').checkBox('changeCheckStatus', true); 	
		},
		function(){
			//$(this).checkBox('changeCheckStatus', false); 	
			$('input[type=checkbox]').checkBox('changeCheckStatus', false); 	
		}
		); 
		
		// Filters 
		
		//jQuery('dl.filters dl').hide(); // To make the filters auto expanded when page is loaded first time
		jQuery('dt.categoryHead').toggle(function(){
			var $this = $(this);
			jQuery(this).next('dd').children('dl').slideUp(function(){
				jQuery($this).removeClass("active");
			});
			
		},
		function(){
			
			jQuery(this).next('dd').children('dl').slideDown();
			jQuery(this).addClass("active");
			
		}
		);
		
		// Select Box Replacement : http://www.scottdarby.com/plugins/stylish-select/0.3/
		
		jQuery('p.sortBy select,.dropDownSelect').sSelect({animationSpeed:0});
		
		// Accordion
		
		
		$('#AccordionList h2.accordionHead').click(function(){
			$(this).next().slideToggle();
			$(this).toggleClass("selected");
			return false;
		}).next().hide();
		
		// Active the first list
		
	//	$('#AccordionList h2.accordionHead:first').next().toggle();
	//	$('#AccordionList h2.accordionHead:first').addClass("selected");
		
		//Acitve all list
		$('#AccordionList h2.accordionHead').next().toggle();
		$('#AccordionList h2.accordionHead').addClass("selected");
		
		// Search Results : Show More Details 
		
		jQuery('ul.searchItems li').children('dl.details').hide();
		jQuery('ul.searchItems a.toggleControl, a.itemImage, ul.searchItems h3').click(function(){
			if(jQuery(this).parents('li').hasClass("active")){
				jQuery(this).parent('li').children('dl.details').slideUp(function(){
				  jQuery(this).parent('li').removeClass("active");
				  });
				jQuery(this).parent('li').children('.toggleControl').children('b').children('b').html("View details <img src='/apps/yoursingapore/resources/traveller/images/en/arrow_down.gif' alt='' />");
			}
			else{
				jQuery(this).parent('li').addClass("active");
				jQuery(this).parent('li').find('dl.details').slideDown();
			  	jQuery(this).parent('li').children('.toggleControl').children('b').children('b').html("Close <img src='/apps/yoursingapore/resources/traveller/images/en/arrow_up_normal.gif' alt='' />");
			}
			return false;
		});
		
		// Toggle Contact Form 
		
		jQuery('a.toggleForm').prev('.forms').hide();
		jQuery('a.toggleForm').toggle(function(){
			jQuery(this).prev('.forms').slideDown();
			jQuery(this).removeClass("arrowDownButton").addClass("arrowUpButton");
			jQuery(this).children('b').children('b').html("close");
		},
		function(){
			jQuery(this).prev('.forms').slideUp();
			jQuery(this).removeClass("arrowUpButton").addClass("arrowDownButton");
			jQuery(this).children('b').children('b').html("Ask now")
		})
		
		// Load Facebox 
		
		jQuery('a[rel*=facebox]').facebox() 
		
		// Quick Look  
		
		jQuery('.resultsRecommend dl dt').mouseover(function(){
			jQuery(this).children('a.quickView').show();
		}).mouseout(function(){
			jQuery(this).children('a.quickView').hide();
		});
		
		// Contact us Faq List
		
		jQuery('dl.faqList dd').hide();
		jQuery('dl.faqList dt, dl.faqList a.arrowUpButton').click(function(){
			if(jQuery(this).parents('dl').children('dt').hasClass("active")){
				jQuery(this).parents('dl').find('dd').slideUp();
				jQuery(this).parents('dl').find('dt').removeClass("active");
			}
			else{
				jQuery(this).parents('dl').find('dd').slideDown();
				jQuery(this).parents('dl').find('dt').addClass("active");
			}
			return false;
		});
		
		
		// Form Validation 
		
		if(jQuery('#SubscribeForm').length){jQuery('#SubscribeForm').validate(); }
		
		if(jQuery('#QuestionForm').length){jQuery('#QuestionForm').validate();}
		
		if(jQuery('#RequestInfoForm').length){jQuery('#RequestInfoForm').validate();}
		
		//$.metadata.setType("attr", "validate");	
		
		if(jQuery('#TellUsExperienceForm').length){jQuery('#TellUsExperienceForm').validate();}
		
		// Add Reference Links 
		
		var count=0;
		var maxcount=4;
		jQuery('#AddLink').click(function(){
			if (count<maxcount){
				count++;
				jQuery('<input type="text" id=link_'+count+' name="referenceLinks[]" />').insertBefore(this);
			}
			return false;
		});
		
		var filecount=0;
		var maxfilecount=2;
		jQuery('#AddFile').click(function(){
			if (filecount<maxfilecount){
				filecount++;
				jQuery('<input type="file" id="file_'+filecount+'" name="fileUploads[]" />').insertBefore(this);
			}
			return false;
		});
		
		// Contact us - Tell us Experience Switching
		
		
		var selectedRadio = jQuery('fieldset.optionSelect input[type=radio]:checked').attr('rel');
		jQuery('#'+jQuery('fieldset.optionSelect input[type=radio]:unchecked').attr('rel')).find('textarea').removeClass("required");
		jQuery('#'+ selectedRadio).slideDown();
		//jQuery('#'+ selectedRadio).children('textarea').removeClass("required");
		jQuery('.optionSelect input[type=radio]').click(function(e){
			e.preventDefault();
			jQuery('#'+selectedRadio).hide();
			jQuery('#'+selectedRadio).find('textarea').removeClass("required")
			
			var rel = $(this).attr("rel");
			selectedRadio = rel;
			jQuery('#'+rel).find('textarea').addClass("required")
			$('#'+rel).show();
			return false;
		});
		
	
});
// Run when page loads
$(document).ready(function(){
						   if ($('img').length) {
							$('img').load(function() {
									jQuery('body.firstLevel .catListing, .catListing').equalHeights(true);

							});
							} else {
									jQuery('body.firstLevel .catListing, .catListing').equalHeights(true);

							}

});
