// JavaScript Document

jQuery.noConflict();
jQuery(document).ready(function($) {
	$("#slideshow").hide();
	$("#smslideshow").hide();
	$("#gallery").cycle({ 
		fx: 'fade',
		timeout: 5000,
		speed: 1000,
		pause: 1,
		fit: 1,
		pager: '#menuslide',
		before:   onBefore 
	});
	
	var totalSlideCount = imgtotal; 
	
	var p = path;
     
    function onBefore(curr, next, opts) { 
        if (!opts.addSlide) {
            return; 
		}
		
        var currentImageNum = parseInt(next.src.match(/p(\d)/)[1]); 
             
        if (currentImageNum == totalSlideCount) { 
            opts.addSlide = null; 
            return; 
        } 
		var c = currentImageNum+1;
        var img = 'p' + c +'.jpg';
		switch(slug){
			case "home":
				w = "832";
				h = "344";
				pe = "slideshow/home";
			break;
			default:
				w = "596";
				h = "380";
				pe = "slideshow/"+slug;
		}
		var me = "<img src=\""+p+"/images/"+pe+"/"+img+"\" width=\""+w+"\" height=\""+h+"\" />";
        opts.addSlide(me); 
    }; 

	$('#pauseBtn').toggle(function() {
		$('#gallery').cycle('pause');
		}, function() {

		$('#gallery').cycle('resume', true);  
	}); 
	
	// Hover
	
	$('ul#mainmenu').css({backgroundPosition: '0px 0px'});
	
	$("ul#mainmenu a").mouseover(function(){
		var m = $(this).attr("id");
		//var me = $(this).closest("ul").attr("id");
		switch(m){
			case "about":
				var c = "-39px";
			break;
			case "home-style":
				var c = "-78px";
			break;
			case "home-features":
				var c = "-117px";
			break;
			case "monterra-life":
				var c = "-156px";
			break;
			case "community-site-plan":
				var c = "-195px";
			break;
			case "cooper-city-life":
				var c = "-234px";
			break;
			case "cc-devco-homes":
				var c = "-273px";
			break;
			case "contact-us":
				var c = "-312px";
			break;
			default:
				var c = "0";
			break;

			
		}
		$('ul#mainmenu').css({backgroundPosition: '0px '+c});
	});
	
	$("ul#mainmenu a").mouseout(function(){
		$('ul#mainmenu').css({backgroundPosition: '0px 0px'});
	});
	
	$("#slideshow").show();
	$("#smslideshow").show();
	
	$("a").filter(function() {
		return this.hostname && this.hostname !== location.hostname;
	}).attr('target', '_blank');

	
});

