// function to make columns height equal
function equalHeight(group) {
    tallest = 0;
    group.each(function() {
        thisHeight = $(this).height();
        if(thisHeight > tallest) {
            tallest = thisHeight;
        }
    });
    group.height(tallest);
}

$(document).ready(function(){
    // reset z-indexes for divs in all browsers in order to fix ie z-index bug
	var zIndexNumber = 100;
	$('.snippet-container, #footer').each(function() {
	  $(this).css('zIndex', zIndexNumber);
	  zIndexNumber -= 10;
	});

    // menu styling
    $('#menu-primary ul li:first a').css('padding-left','14px');
    $('#menu-primary ul li:last-child').not('#menu-primary ul li ul li:last-child').css('background','none');
    $('#menu-primary ul li:last-child > ul').not('#menu-primary ul li ul li ul:last-child').css('margin-left','-22px');
    
	//$('.content-container table th:last-child').css('background','#ffd100 url(css/images/bkg_table-header.gif) no-repeat bottom right');

    // append rounded corner image for last list item in secondary nav
    $('.secondary-nav ul.options li:last').append('<span class="corner" />');
    
    // custom select drop down
    //$('#quicklinks, .snippet select').SelectCustomizer();

    // make snippets height equal
    equalHeight($('.node'));   
    equalHeight($('.preview')); 
    
    // intialize sliding content snippets
    $('.highlights').loopedSlider({
    	//autoStart: 6000,
    	//restart: 6000
    });
    $('#promotion').loopedSlider({
        autoStart: 5000,
        restart: 5000
    });    
    
    // initialize tabs
    var $container = $('.content-container');
    if ($container.find('ul.tab-nav').length) {
        $container.tabs();
    }
    
    // initialize accordion
	$('.answer').hide();
	$('div.question').click(function(){
	    $(this).toggleClass('open');
		$(this).next().slideToggle(500);
		return false;
	});
	
	// page title background image
	if ($('#page-title').find('img').length != 0 ) {
	    var bkg = $('#page-title').find('img').attr('src');
		$('#page-title').css('background-image', 'url(' + escape(bkg) + ')');
		$('#page-title').find('img').hide();
		$('#page-title h2, #page-title h4').css('padding-right','305px');
		if (($.browser.msie && $.browser.version.substr(0,1)<7)) {	
			$('#page-title').css('padding-top','0');
		}
		try {
			document.getElementById('page-title').style.backgroundRepeat = 'no-repeat';		
		}
		catch (anError) {}
	}
	if ($('#alt-page-title').find('img').length != 0 ) {
	    var altbkg = $('#alt-page-title').find('img').attr('src');
		$('#alt-page-title').css('background-image', 'url(' + escape(altbkg) + ')');
		$('#alt-page-title').find('img').hide();
		$('#page-title h2, #page-title h4').css('padding-left','305px');
		if (($.browser.msie && $.browser.version.substr(0,1)<7)) {	
			$('#alt-page-title').css('padding-top','0');	
		}
		try {
			document.getElementById('alt-page-title').style.backgroundRepeat = 'no-repeat';		
		}
		catch (anError) {}
	}	
	
	$(function(){
	  //If browser is IE, disable BackgroundImageCache
	  if (jQuery.browser.msie) {
	    try {
	      document.execCommand(
	        "BackgroundImageCache",
	        false, 
	        true);
	    } catch(err){}
	  }
	});	
	
	// menu targeting firefox only
	if ($.browser.mozilla) {
		$('.vgn-ext-ice-floatee-menu-outer-div').css('top','-182px');
	}
});