$(document).ready(function (){
    
	// apply equal height on listing divs
    if ($('#featured-listings .listing').length > 0) {
        $('#featured-listings .listing').equalHeights(0, 202);
    }
    
    if ($('.new-arrivals .listing').length > 0) {
        $('.new-arrivals .listing').equalHeights(0, 202);
    }
    
    if ($('.ad-list .featured .listing').length > 0) {
        $('.ad-list .featured .listing').equalHeights(0, 255);
    }
    
    if ($('.ad-list .basic .listing').length > 0) {
        $('.ad-list .basic .listing').equalHeights(0, 220);
    }
    
    // Pro Shop Page
    if ($('#ad-list .listing').length > 0) {
        $('#ad-list .listing').equalHeights(0, 220);
    }
    
    // Ajax call to fetch affiliate ads
    if ($('#affiliate-ajax').length > 0) {
        
        $.ajax({
            url: $('#affiliate-ajax').attr('data-url'),            
            success: function(data, textStatus, XMLHttpRequest){
                $('#affiliate-ajax').html(data);
            }            
        });
    }
    
    /**
     * Listen on listing div and redirect user to the listing page on click
     *
     */
    $('.listing').click(function() {
    	var href = $('.descritpion h3 a', this).attr('href');
    	window.location.href = href;
    	
    });
    
});

/**
 * Handle tabs on listing detail page
 */
function openTab(id, what)
{
    $(".a_tabs").each(function(){
        $(this).removeClass('current');
    });
     
    $(".description").each(function(){
        $(this).hide();
    });
		
    $('#' + id).addClass("current");
    $('#' + what).show();
}
