/**
 * Avenidas home page JS.
 * 
 * 
 */

/**
 * Runs on document load.
 * 
 * 
 */
$(document).ready(function() {
    var tn = $('#tab_nav').children('li');
    for (var i = 0; i < tn.length; i++) {
        if ($(tn[i]).find('.sub').length) {
            $(tn[i]).bind('mouseover', tabNavOver);
            $(tn[i]).bind('mouseout', tabNavOut);
        }
    }
    // Get circle navigation <li> elements.
    var cn = $('#circle_nav').children('li');
    // Assign over/out handlers.
    for (var i = 0; i < cn.length; i++) {
        $(cn[i]).bind('mouseover', circleNavOver);
        $(cn[i]).bind('mouseout', circleNavOut);
    }


	$('#home_img>ul').cycle({speed: 1000, timeout: 8000, autostop:0,height: 297});
	$('#animate').cycle({speed: 1000, timeout: 8000, autostop:0});
	$('#circle_nav_services').click(function(){
		window.location = base_url + 'services';
	});
	$('#circle_nav_activities').click(function(){
		window.location =  base_url + 'activities';
	});
	$('#circle_nav_we').click(function(){
		window.location = base_url + 'we';
	});
	$('#circle_nav_you').click(function(){
		window.location = base_url + 'you';
	});
	
	// IE fix to offset transparent png fix that disables links
	if ($.browser.msie){
		$('#tab_nav li').click(function(){
			window.location = $('a', this).attr('href');
		});
	}

});


/**
 * Mouseover for the tab nav.
 * 
 * 
 */
function tabNavOver() {
    $(this).addClass('active');
}


/**
 * Mouseout for the tab nav.
 * 
 * 
 */
function tabNavOut() {
    $(this).removeClass('active');
}


/**
 * Shows circle nav contents, sets backgrounds, etc.
 * 
 * 
 */
function circleNavOver() {
    var id_suffix = getCircleNavIdSuffix($(this).attr('id'));
    $('#cn_bg_' + id_suffix).show();
    $(this).children('ul').show();
}


/**
 * Hides circle nav contents, sets backgrounds, etc.
 * 
 * 
 */
function circleNavOut() {
    var id_suffix = getCircleNavIdSuffix($(this).attr('id'));
    $('#cn_bg_' + id_suffix).hide();
    $(this).children('ul').hide();
}


/**
 * Gets id of the circle nav <li>, sans "circle_nav_". This is used to match up
 * with the #cn_bg_* placeholders.
 * 
 * 
 */
function getCircleNavIdSuffix(id) {
    return (/^circle_nav_(.*)$/).exec(id)[1];
}


