// JavaScript Document
$(function(){

	Yeoman = new function(){
		
		this.init = function(){
			
			$(".affiliate-open").click(function(){
				if($("#footer #footer-logos").css('height') == '66px'){
					$("#footer #footer-logos").stop().animate({height: '0px'},200);
					$("#footer").stop().animate({marginTop: '-26px'});
				} else {
					$("#footer #footer-logos").stop().animate({height: '66px'},200);
					$("#footer").stop().animate({marginTop: '-92px'});
				}
				return false;
			});
			
			/*if($("#footer #footer-logos").css('height') == '66px'){
					$("#footer #footer-logos").stop().animate({height: '0px'});
					
				} else {
					$("#footer #footer-logos").stop().animate({height: '66px',});
					
				}*/
			
			$("select").selectmenu({style: 'dropdown', width: '130px', height: '27px'});
			
			$(".hide-tab").hide();
	
			$(".more-info").each(function(i,el){
				if($(el).hasClass("dont-hide")){
					
				} else $(el).hide();
			});
		
			var obj = $("input[name=postcode]");
			$(obj).focus(function(){
		 		if(obj.val() == 'keyword/postcode'){
					obj.val('');
				}
		 	});
			$(obj).blur(function(){
		 		if(obj.val() == ''){
					obj.val('keyword/postcode');
				}
		 	});
			
			$("#menu ul li a img").each(function(){
				var src = $(this).attr('src');
				var new_src = src.replace('-off','-on');
				if(src == new_src) $(this).addClass('current');
			});
			
			$("#menu ul li a img").mouseover(function(){
				if(!$(this).hasClass('current')){
					var src = $(this).attr('src');
					var update = Yeoman.changeTag(src);
					$(this).attr('src',update);
				}
			});
			
			$("#menu ul li a img").mouseleave(function(){
				if(!$(this).hasClass('current')){
					var src = $(this).attr('src');
					var update = Yeoman.changeTag(src);
					$(this).attr('src',update);
				}
			});
			
		}
		
		$("a[rel=rental-search]").click(function(){
			$("img",$(this)).attr('src','/images/tab-rental-search-on.png');
			$("img",$("a[rel=property-search]")).attr('src','/images/tab-property-search-off.png');
	 		$("#property-search").css('display','none');
	 		$("#rental-search").css('display','block');
			return false;
	 	});
		$("a[rel=property-search]").click(function(){
			$("img",$(this)).attr('src','/images/tab-property-search-on.png');
			$("img",$("a[rel=rental-search]")).attr('src','/images/tab-rental-search-off.png');
	 		$("#rental-search").css('display','none');
	 		$("#property-search").css('display','block');
			return false;
	 	});
		
		this.changeTag = function(src){
			if(src.length > 0){
				new_src = src.replace('-off','-on');
				if(new_src == src){
					new_src = src.replace('-on','-off');
					return new_src;
				} else return new_src;
			}
		}
	}
	
	Yeoman.init();
	
	var parent_obj = $(".home-gallery"); // parent div
	var img_count = ($("img",parent_obj).length - 1); // pause/play button
	var img_reset = img_count;
	var play_speed = 5000; // auto speed
	var image_class = 'gallery-image';
	var restarter = '';
	
	var num_slides = $('.gallery-image').length;
	var current_slide = 1; //num_slides;
	
	
	/* Successful Pause/Play functionality */
	var cycle_interval = setInterval(function(){gallery_cycle();},4000);
	
	$(".control").click(function(){
		if(!$(this).hasClass('stopped')){
			$(this).addClass('stopped');
			$(this).attr('src','/images/button-play.png');
			$(this).attr('rel','paused');
			clearInterval(cycle_interval);
		} else {
			$(this).removeClass('stopped');
			$(this).attr('src','/images/button-pause.png');
			$(this).attr('rel','');
			cycle_interval = setInterval(function(){gallery_cycle();},4000);
		}
		return false;
	});
	
	function gallery_cycle(){
		if((current_slide*1)==num_slides){
			current_slide = 1;
			$('.gallery-image').fadeIn();
		}else{
			$('#image_'+current_slide).fadeOut();
			current_slide = (current_slide*1)+1;
		}
	}
	
	setTimeout(function(){$('.gallery-image').fadeIn()},2000);
});
