var current = new Array();
current['featured_service'] = 1;
current['tips-and-tricks'] = 1;
current['testimonials'] = 1;

jQuery(document).ready( function() { 

    if ( jQuery('#featured-services_1').is(':hidden') ) { 

        // This is the home page.

        var featured_services_id = Math.ceil( Math.random() * jQuery('.featured-services').length);
        var tips_and_tricks_id = Math.ceil( Math.random() * jQuery('.tips-and-tricks').length);
        var testimonials_id = Math.ceil( Math.random() * jQuery('.testimonials').length);

        jQuery('#featured-services_' + featured_services_id).show().click( function() { top.location='/category/featured-services'; } );
        jQuery('#tips-and-tricks_' + tips_and_tricks_id).show().click( function() { top.location='/category/tips-and-tricks'; } );
        jQuery('#testimonials_' + testimonials_id).show().click( function() { top.location='/category/testimonials'; } );

    }

    jQuery('ul.menu img').hover(
        function() { 
            jQuery(this).attr('src', '/wp-content/themes/mrplumber/images/menu_' + jQuery(this).attr('menuname') + '_on.jpg'); 
        },
        function() { 
            if (jQuery(this).attr('do_not_change') != '1') { 
                jQuery(this).attr('src', '/wp-content/themes/mrplumber/images/menu_' + jQuery(this).attr('menuname') + '.jpg'); 
            }
        }
    );


} );



function rotate_content( category ) {

    var next_item = (current[ category ] * 1) + 1;

    if ( ! jQuery('#' + category + '_' + next_item).is(':hidden') ) {
        next_item = 1;
    }

    jQuery('#' + category + '_' + current[ category ]).fadeOut('slow', function() { 
        jQuery('#' + category + '_' + next_item).fadeIn('slow')
    });

    current[category] = next_item;

    var timeout = 8000;
    if (category == 'testimonials') { timeout = 16000; }

    setTimeout("rotate_content('" + category + "');", timeout);

}


function get_product_detail( id ) {

    jQuery.get("/products/detail", { product_id: id }, function(data) {
        var data_parts = data.split(",,", 3) 
        jQuery('#product_detail').html(data_parts[2]);

        var new_width = data_parts[0];

        var container_width = (new_width * 1) + 4;

        jQuery('#product_detail_container_container').css('width', container_width + "px");
        jQuery('#product_detail_container').css('width', new_width + "px");

        jQuery('#product_detail_container_container').css('margin', '0 auto');

        jQuery('#container').fadeTo('normal', 0.2);
        jQuery('#product_detail_container').fadeIn('normal');
    } );

}

function close_product_detail() { 

    jQuery('#product_detail_container').fadeOut('normal');
    jQuery('#container').fadeTo('normal', 1.0);

}



function browser_dimensions() {
     var dimensions = {width: 0, height: 0};
     if (document.documentElement) {
         dimensions.width = document.documentElement.offsetWidth;
         dimensions.height = document.documentElement.offsetHeight;
     } else if (window.innerWidth && window.innerHeight) {
         dimensions.width = window.innerWidth;
         dimensions.height = window.innerHeight;
     }
     return dimensions;
}

