$(document).ready(function() {
	var currenturl = location.pathname.split('/')[1];
	var newhref = '/'+currenturl+'/contact-us.php';
	switch(currenturl) {
        case 'dallas':
        case 'denver':
        case 'houston':
        case 'omaha':
        case 'college-station':
            $('li#utility-contact-us a,li#primary-contact a').attr('href', newhref);
    }
});
$(function() {
	
	// Masthead scaler
	if ($("body.scale").length>0) {
		mastheadScaler(); // Run 1st time for FF
		var scaleTimer;
		$(window).resize(function() {
			clearTimeout(scaleTimer);
			scaleTimer = setTimeout(mastheadScaler, 50);
		});

	}
	
	//Documentation located in special.docs.js
	$('#home-push-carousel').jcarousel({
		scroll: 1,
		visible: 3,
		wrap: 'circular',
		initCallback: mycarousel_initCallback
	});
	
	$('#property-promos').after('<div id="control-links">').cycle({ 
		fx:     'scrollLeft', 
		speed:  1000, 
		timeout: 5000, 
		next: '.next-link',
		pager:  '#control-links',
		before: function(){ $("#control-links").hide();},
		after: function(){ $("#control-links").fadeIn(); }
	});
	
	$('#property-promos').mouseover(function() {
		$(this).cycle('pause'); 
	}).mouseout(function() {
		$(this).cycle('resume'); 
	});
	
	
	$('.blog-comment').hide();
	$('.hide-comments').hide();

	$('.post-comments a').click(function(e) {
	    e.preventDefault();
	    $(this).parent().toggleClass("active").parents(".post").children('.blog-comment').toggle();
	});
	
	$('.post-comment-total a').click(function(e) {
	    e.preventDefault();
	    $(this).parent().toggleClass("active").parents(".post").children('.comments-posted').toggle();
	});
	
	$('.blog #archive-months').change(function() {
		if ($(this).val()!='') {
			window.location.href=$(this).val();
		}
	});
});

function mycarousel_initCallback(carousel) {
	// Pause autoscrolling if the user moves with the cursor over the clip.
	carousel.clip.hover(function() {
		carousel.stopAuto();
	}, function() {
		carousel.startAuto();
	});
};

function mastheadScaler() {
	var mastH = $('#masthead').attr("mastH");
	var mastW = $('#masthead').attr("mastW");
	var winW = $(window).width();
	var newH = Math.ceil(winW*mastH/mastW);
	$('body.scale #masthead').css('height', newH);
};
