//equal heights function - matches heights of a group of elements to the largest 
function equalHeight(group) {
	tallest = 0;
	group.each(function() {
		thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}

$(function(){
	
	// load the flash version of the image
    if ( $('#flash-container').size() > 0 ) {
        var so = new SWFObject("_common/flash/bg-01.swf", "flash-background", "100%", "100%", "6");
        so.addParam("movie", "_common/flash/bg-01.swf");
        so.addParam("quality", "high");
        so.addParam("wmode", "transparent");
        so.write("flash-container");
    }

    // wrap pipe character	
    var f = $("#center");
	if (f.size() > 0)
    	f.html( f.html().replace(/\|/g,"<span class=\"pipe\">|</span>") ); 

    // set equal heights on offers
    // group by rows    
    $('.service-page .inner').children('.offer:eq(0)').addClass('row1');
    $('.service-page .inner').children('.offer:eq(1)').addClass('row1');

    $('.service-page .inner').children('.offer:eq(2)').addClass('row2');
    $('.service-page .inner').children('.offer:eq(3)').addClass('row2');

    $('.service-page .inner').children('.offer:eq(4)').addClass('row3');
    $('.service-page .inner').children('.offer:eq(5)').addClass('row3');

    // set equal heights per row
    equalHeight($('.row1'));
    equalHeight($('.row2'));
    equalHeight($('.row3'));


    // append span.plus to all center h3
    $('#center .service h3').append('&nbsp;<span class="plus">[more]</span>');

    // apply fancybox to contact-us links
    $('a[href*="contact-us"]').each(function(){
        var thisUrl = $(this).attr('href');
        $(this).attr('href',  thisUrl + '?iframe');
        $(this).fancybox({
            'frameHeight': 550,
            'zoomOpacity' : true,
            'overlayShow' : false,
            'zoomSpeedIn' : 0,
            'zoomSpeedOut' : 0,
            'hideOnContentClick': false,
            'overlayShow': true,
            'overlayOpacity': .9
        });
    });
    
	$('#center .service h2 a, #center .service h3').each(function() {
		$(this).click(function() {
            thisInner = $(this).parents('.service').find('.inner');
            sHeight = thisInner.height() + 200;

            if ( $(this).parents('.service').hasClass('open') ) {
                $(this).parents('.service').stop().animate({
                    height: '200px'
                }, 500, 'easeOutQuad' );
                //swap + - and set open class
                $(this).parents('.service').removeClass('open').find('span.plus').html('[more]');
            } else {
                $(this).parents('.service').stop().animate({
                    height: sHeight
                }, 500, 'easeInQuad' );
                //swap + - and set open class
                $(this).parents('.service').addClass('open').find('span.plus').html('[less]');
            }

            return false;
		});
	});

	$('#center .service').each(function() {
        $(this).click(function(){
            if ( $(this).height() == 200 ) {
                $(this).find('h2 a').click();
                return false;
            }
        });
        $(this).children().click(function(){
            
        });
    });

    // make entire block clickable
/*
    $('#center .service').click(function(){
        $(this).find('h2 a').trigger('click');
    });
*/	
	// zebra stripe services
	$('#center .service:odd').addClass('odd');


});