// JQUERY
$.fn.pause = function(duration) {
    $(this).animate({ dummy: 1 }, duration);
    return this;
};
function alerte(obj) {
	if (typeof obj == 'object') {
		var foo = '';
		for (var i in obj) {

				foo += '[' + i + '] => ' + obj[i] + '\n';
		}
		alert(foo);
	}
	else {
		alert(obj);
	}
}


$(document).ready(function() {
	
	// ALTERNATE ROW COLORS FOR TABLE #ALTERNATE_COLORS
	$("tr:even").css("background-color", "#FFF");
  	$("tr:odd").css("background-color", "#FFF");
	$("tr").hover(function(){
	   $(this).css("background","#EEE");
	 },function(){
	   	$("tr:even").css("background-color", "#FFF");
	   	$("tr:odd").css("background-color", "#FFF");
	 });
	// INSERT USER2WEBSITE
	$("#adduser2website").click(function(){
		var str = $("#input").serialize();
		$.post("admin/user/adduser2websites/",str,function(data) {
	 	});
	});

	// SWITCHER REDIRECT
	
	$("#switcher_selector").change(function() {
	  document.location = this.value;
	});
	
	// ADMIN SUBMENU NAVIGATION
	var subs = $('#menu > ul ul');
	
    $('#menu .mainmenu').hover(function(){
                  subs.hide();
				  $(this).next('#menu > ul > ul').show();
				  $(this).css('border:1px solid red')
				  
            },
		
				function(){
					$(this).addClass('hover');		
			}); 
	// SHOW THE SEARCHFORM
	$('#searchinput').click(function(){
		$('#searchform').show('slow');
	});
	
	// CAROUSEL
	
	
	// equalheights
	
	//$('#sidebar,#content').equalHeights(500,0);
	 
	 // PICASA WEB GALLERY
	 
		/* This is basic - uses default settings 
	
		$("a.grouped_elements").fancybox();
		$(".item").click(function(){alert('');return false;});
*/
	 	//$('#nivo_slider').nivoSlider();
	
	// highlight links
	
	$('#menu li a').hover(function(){
		$("#menu li").removeClass();
		$(this).parent('li').addClass('menuhover');
	},function(){
		$(this).parent('li').removeClass('menuhover');
	});
	$('#menu li a').click(function(){
		});


	$(function(){
		$page = window.location;
		if(!$page) {
			$page = 'index.html';
		}
		$('ul.colleft_links li a').each(function(){
			var $href = $(this).attr('href');
			if ( ($href == $page) || ($href == '') ) {
				$(this).addClass('on');
			} else {
				$(this).removeClass('on');
			}
		});
		$('#menu li a').each(function(){
			var $href = $(this).attr('href');
			if ( ($href == $page) || ($href == '') ) {
				$(this).parent('li').addClass('menuhover');
			} else {
				$(this).removeClass('menuhover');
			}
		});

	});
	// SEARCHBOX
	$('#search_property').click(function(){
		$('#searchbox').slideDown();
	});
	
	

	// slidedeck
	//$('dl#slidedeck').slidedeck();
	
	// contact form submit 
	$("#contactform").submit(function(){
		
		// check the form values
		var name = $('#contactform #name').val();
		var email = $('#contactform #email').val();
		var message = $('#contactform #message').val();
		if(name == ""){ alert('please enter a name'); $('#contactform #name').css('border','1px solid red');return false;}
		if(email == ""){ alert('please enter a valid email'); $('#contactform #email').css('border','1px solid red');return false;}
		if(message == ""){ alert('please enter a message'); $('#contactform #message').css('border','1px solid red');return false;}
		
		$('#contact-wrapper').html('<h1 style="padding-top:100px"><center>Sending your message</center></h1>');
		$('#contact-wrapper').css('background-image','url(/loader.gif)');
		$('#contact-wrapper').css('backgroundPosition','center center');
		$('#contact-wrapper').css('background-repeat','no-repeat');
		// ajax
		var str = $(this).serialize();
		$.post("homesite/sendContactEmail/",str,function(data) {
			$('#contact-wrapper').html('<center><h1 style="padding-top:100px">Your message has been sent !</h1><p><center>We will get back to you very shortly.</center></p></center>');
			$('#contact-wrapper').css('background-image','').pause(5000);
			$('#contact-wrapper').fadeOut();
			parent.location.reload(); 
	 	});
		// load result
		return false;
	});
	
	// home slideshow
	$("#slideshow .slideshow_nav h2").hover(function(){
		$(this).css("background-image","url('sites/coronadocoastalliving.com/css/pt_black_60.png')");
		$(this).append('<div class="slideshow_pager"></div>');
	},function(opts){
		$(this).css("background-image","url('')");
		$('.slideshow_pager').hide();
	});
	$('#image_slide').cycle({
		fx: 'fade'
		/*
		easeIn:   function() {
	        var title = $('#image_slide img').attr('alt');
	        $('#image_slide_caption').html(title);
    	
    	}*/
	});
		
	 $('#slideshow_container').cycle({
		fx: 'fade',
		speed:  2500 , 
		timeout: 4000, 
		autostop:4,
		before: onBefore1 ,
		after: onAfter1,
		end:onAfter2
 	});

	function onAfter1(curr,next,opts) {
			var title = $(this).attr('alt');
			$('.goto'+ opts.currSlide).css("background-image","url('sites/coronadocoastalliving.com/css/pt_black_60.png')");
			$('.goto'+ opts.currSlide).append('<div class="slideshow_pager"></div>');
			$('.image_title').fadeIn("slow").html(title);	
    	}
	function onAfter2(curr,next,opts) {
		$('.image_title').hide();
		$('.slideshow_action').animate({width:'toggle'},320);
        
	}
	function onBefore1(curr,next,opts){
			$('.slideshow_pager').hide();
			$('.image_title').fadeOut();
			$('.goto'+ opts.currSlide).css("background-image","url('')");
			
			}
			
 	function pagerFactory(idx, slide) {
		var s = idx > 2 ? ' style="display:none"' : '';
		return '<li'+s+'><a href="#">'+(idx+1)+'</a></li>';
	}; 
	
	$('.goto0').hover(function() {
		$('#slideshow_container').cycle(0).cycle('pause'); 
	    return false; 
	},function(){$('#slideshow_container').cycle('resume')});
	 
	$('.goto1').hover(function() { 
		$('#slideshow_container').cycle(1).cycle('pause'); 
	    return false; 
	},function(){$('#slideshow_container').cycle('resume')});
	 
	$('.goto2').hover(function() { 
		$('#slideshow_container').cycle(2).cycle('pause'); 
	    return false; 
	},function(){$('#slideshow_container').cycle('resume')}); 
	
	$('.goto3').hover(function() { 
	    $('#slideshow_container').cycle(3).cycle('pause'); 
	    return false; 
	},function(){$('#slideshow_container').cycle('resume')}); 
	

	$('.goto0').click(function() {
		window.location = 'http://www.coronadocoastalliving.com/'; 
	});
	$('.goto1').click(function() {
		window.location= 'http://www.coronadocoastalliving.com/realestate'; 
	});
	$('.goto2').click(function() {
		window.location = 'http://www.coronadocoastalliving.com/page/coronado_living'; 
	});
	$('.goto3').click(function() {
		window.location = 'http://www.coronadocoastalliving.com/page/about_us'; 
	});



	$('.slideshow_goto').hover(function(){
		$(this).css("background-image","http://www.coronadocoastalliving.com/sites/coronadocoastalliving.com/css/pt_black_60.png");
	});


	
});

