$(document).ready(function() {
    $(".competitor .block").click(function(){
	_gaq.push(['_trackPageview', '/competitor/from/' + supplierTnid]);

	if (!jQuery.browser.msie) {
	    window.location = $(this).find("a").attr("href");
	    return false;
	}
		
	var a = document.createElement("a");
	a.setAttribute("href", $(this).find("a").attr("href"));
	a.style.display = "none";
	$("body").append(a);
	a.click();
		
	return false;
    });

    var anchor = jQuery.url.attr("anchor") ? jQuery.url.attr("anchor") : (SS.defaultTab ? SS.defaultTab : 'profile');
	
    if (anchor == 'catalogue')
    {
	$('#profile').hide();
	$('#contact_content').hide();
	$('div.profile_address_container').hide();
	$('#map_box').hide(); 
	$('#catalogue_box').show();
	$('#reputation_box').hide();
	$('#svp_playerc88myyri0eg4').hide();
	$('html, body' ).animate( {
	    scrollTop: 0
	}, 0 );
	$('li#catalogue_toggle').removeClass('off').addClass('on');
	$('li#profile_toggle').removeClass('on').addClass('off');
	$('li#contact_toggle').removeClass('on').addClass('off'); 
	$('li#map_toggle').removeClass('on').addClass('off');
	$('li#reviews_toggle').removeClass('on').addClass('off');
	$('#sign-in-link').attr('href', '/user/register-login/?returnUrl=' + $.URLEncode(window.location));
	$('#join-link').attr('href', '/user/register-login/?returnUrl=' + $.URLEncode(window.location) + '#reg');
    }
    else if(anchor == 'contact_box') 
    {
	$('#svp_playerc88myyri0eg4').hide();
	$('#profile').hide();
	$('#catalogue_box').hide();
	$('#map_box').hide();
	$('#contact_content').show();
	$('div.profile_address_container').show();
	$('#reputation_box').hide();
	$('html, body' ).animate( {
	    scrollTop: 0
	}, 0 );
	if (isLoggedIn)
	{
	    _gaq.push(['_trackPageview', '/supplier/profile/contact-details-viewed/']);
	}
	
	$('li#contact_toggle').removeClass('off').addClass('on');
	$('li#profile_toggle').removeClass('on').addClass('off');
	$('li#catalogue_toggle').removeClass('on').addClass('off');
	$('li#map_toggle').removeClass('on').addClass('off');
	$('li#reviews_toggle').removeClass('on').addClass('off');
	$('#sign-in-link').attr('href', '/user/register-login/?returnUrl=' + $.URLEncode(window.location));
	$('#join-link').attr('href', '/user/register-login/?returnUrl=' + $.URLEncode(window.location) + '#reg');
	$.get('/supplier/log-contact-viewed/format/json/getprofilerecid/'+getProfileRecId, function(data){});
    }
    else if(anchor == 'map') 
    {
	$('#profile').hide();
	$('#catalogue_box').hide();
	$('#map_box').show();
	$('#contact_content').hide();
	$('div.profile_address_container').hide();
	$('#reputation_box').hide();
	$('html, body' ).animate( {
	    scrollTop: 0
	}, 0 );
	$('li#contact_toggle').removeClass('on').addClass('off');
	$('li#profile_toggle').removeClass('on').addClass('off');
	$('#svp_playerc88myyri0eg4').hide();
	$('li#catalogue_toggle').removeClass('on').addClass('off');
	$('li#reviews_toggle').removeClass('on').addClass('off');
	$('li#map_toggle').removeClass('off').addClass('on'); 
	$('#sign-in-link').attr('href', '/user/register-login/?returnUrl=' + $.URLEncode(window.location));
	$('#join-link').attr('href', '/user/register-login/?returnUrl=' + $.URLEncode(window.location) + '#reg');
    }
    else if(anchor == 'reviews')
    {
	$('#profile').hide();
	$('#catalogue_box').hide();
	$('#map_box').hide();
	$('#contact_content').hide();
	$('div.profile_address_container').hide();
	$('#reputation_box').show();
	$('#svp_playerc88myyri0eg4').hide();
	$('html, body' ).animate( {
	    scrollTop: 0
	}, 0 );
	$('li#contact_toggle').removeClass('on').addClass('off');
	$('li#profile_toggle').removeClass('on').addClass('off');
	$('li#catalogue_toggle').removeClass('on').addClass('off');
	$('li#map_toggle').removeClass('on').addClass('off');
	$('li#reviews_toggle').removeClass('off').addClass('on');
	$('#sign-in-link').attr('href', '/user/register-login/?returnUrl=' + $.URLEncode(window.location));
	$('#join-link').attr('href', '/user/register-login/?returnUrl=' + $.URLEncode(window.location) + '#reg');
		
	var suplierURL = jQuery.url.segment(jQuery.url.segment()-1);
	$.get('/reviews/supplier/s/'+suplierURL, function(data) {
	    $('#reputation_box').html(data);
	});
    }
    else
    {
	$('#contact_content').hide();
	$('div.profile_address_container').hide();
	$('#catalogue_box').hide();
	$('#map_box').hide();
	$('#profile').show();
	$('#svp_playerc88myyri0eg4').show();
	$('#reputation_box').hide();
	$('html, body' ).animate( {
	    scrollTop: 0
	}, 0 );
	$('li#profile_toggle').removeClass('off').addClass('on');
	$('li#contact_toggle').removeClass('on').addClass('off');
	$('li#catalogue_toggle').removeClass('on').addClass('off');
	$('li#reviews_toggle').removeClass('on').addClass('off');
	$('li#map_toggle').removeClass('on').addClass('off');
    }
	
    $('li a.profile_toggle').click(function () {
	$('#contact_content').hide();
	$('div.profile_address_container').hide();
	$('#catalogue_box').hide();
	$('#map_box').hide();
	$('#reputation_box').hide();
	$('#profile').show(); 
	$('#svp_playerc88myyri0eg4').show();
	$('li#profile_toggle').removeClass('off').addClass('on');
	$('li#contact_toggle').removeClass('on').addClass('off');
	$('li#catalogue_toggle').removeClass('on').addClass('off');
	$('li#map_toggle').removeClass('on').addClass('off');
	$('li#reviews_toggle').removeClass('on').addClass('off');
	window.location.hash = '';
	return false;
    });
	
    $('li a.contact_toggle').click(function () {
	$('#svp_playerc88myyri0eg4').hide();
	$('#profile').hide();
	$('#catalogue_box').hide();
	$('#map_box').hide();
	$('#contact_content').show();
	$('div.profile_address_container').show();
	$('#reputation_box').hide();
	if (isLoggedIn) {
	    _gaq.push(['_trackPageview', '/supplier/profile/contact-details-viewed/']);
	}
	$('li#contact_toggle').removeClass('off').addClass('on');
	$('li#profile_toggle').removeClass('on').addClass('off');
	$('li#catalogue_toggle').removeClass('on').addClass('off');
	$('li#map_toggle').removeClass('on').addClass('off');
	$('li#reviews_toggle').removeClass('on').addClass('off');
	$('#sign-in-link').attr('href', '/user/register-login/?returnUrl=' + $.URLEncode(window.location + '#contact_box'));
	$('#join-link').attr('href', '/user/register-login/?returnUrl=' + $.URLEncode(window.location + '#contact_box') + '#reg');
	$.get('/supplier/log-contact-viewed/format/json/getprofilerecid/'+getProfileRecId, function(data){});
	window.location.hash = 'contact_box';
	return false;
    });
	
    $('li a.map_toggle').click(function () {
	$('#profile').hide();
	$('#contact_content').hide();	
	$('#map_box').show();
	$('div.profile_address_container').hide();
	$('#catalogue_box').hide();
	$('#reputation_box').hide();
	$('#svp_playerc88myyri0eg4').hide();	
	$('li#catalogue_toggle').removeClass('on').addClass('off');
	$('li#profile_toggle').removeClass('on').addClass('off');
	$('li#contact_toggle').removeClass('on').addClass('off');
	$('li#reviews_toggle').removeClass('on').addClass('off');
	$('li#map_toggle').removeClass('off').addClass('on');
	$('#sign-in-link').attr('href', '/user/register-login/?returnUrl=' + $.URLEncode(window.location + '#catalogue'));
	$('#join-link').attr('href', '/user/register-login/?returnUrl=' + $.URLEncode(window.location + '#catalogue') + '#reg');
	window.location.hash = 'map';
	return false;
    });
	
    $('div.map').click(function () {
		$('#svp_playerc88myyri0eg4').hide();	
		$('#profile').hide();
		$('#contact_content').hide();
		$('#map_box').show();
		$('div.profile_address_container').show();		
		$('#catalogue_box').hide();
		$('#reputation_box').hide();
		//$( 'html, body' ).animate( { scrollTop: 0 }, 0 );  
		$('li#catalogue_toggle').removeClass('on').addClass('off');
		$('li#profile_toggle').removeClass('on').addClass('off');
		$('li#contact_toggle').removeClass('on').addClass('off');
		$('li#reviews_toggle').removeClass('on').addClass('off');
		$('li#map_toggle').removeClass('off').addClass('on');
		window.location.hash = 'map';
		return false;
    });
	
    $('li a.catalogue_toggle').click(function () {
	$('#svp_playerc88myyri0eg4').hide();
	$('#profile').hide();
	$('#contact_content').hide();
	
	$('#map_box').hide();
	$('div.profile_address_container').hide();
	$('#catalogue_box').show();
	$('#reputation_box').hide();
	//$( 'html, body' ).animate( { scrollTop: 0 }, 0 );  
	$('li#catalogue_toggle').removeClass('off').addClass('on');
	$('li#profile_toggle').removeClass('on').addClass('off');
	$('li#contact_toggle').removeClass('on').addClass('off');
	$('li#map_toggle').removeClass('on').addClass('off');
	$('li#reviews_toggle').removeClass('on').addClass('off');
	$('#sign-in-link').attr('href', '/user/register-login/?returnUrl=' + $.URLEncode(window.location + '#catalogue'));
	$('#join-link').attr('href', '/user/register-login/?returnUrl=' + $.URLEncode(window.location + '#catalogue') + '#reg');
	window.location.hash = 'catalogue';
	return false;
    });

    $('li a.reviews_toggle').click(function () {
	$('#svp_playerc88myyri0eg4').hide();
	$('#contact_content').hide();
	$('div.profile_address_container').hide();
	$('#catalogue_box').hide();
	$('#map_box').hide();
	$('#profile').hide();
	$('#reputation_box').show();
	//$( 'html, body' ).animate( { scrollTop: 0 }, 0 );
	$('li#profile_toggle').removeClass('on').addClass('off');
	$('li#contact_toggle').removeClass('on').addClass('off');
	$('li#catalogue_toggle').removeClass('on').addClass('off');
	$('li#map_toggle').removeClass('on').addClass('off');
	$('li#reviews_toggle').removeClass('off').addClass('on');
	var suplierURL = jQuery.url.segment(jQuery.url.segment()-1);
	$.get('/reviews/supplier/s/'+suplierURL, function(data) {
	    $('#reputation_box').html(data);
	});
	window.location.hash = 'reviews';
	return false;
    });
	
    $('li a.catalogue_toggle').live('click',function (e) {
	$('#svp_playerc88myyri0eg4').hide();
	$('#profile').hide();
	$('#contact_content').hide();
	$('div.profile_address_container').hide();
	$('#map_box').hide();
	$('#catalogue_box').show();
	$('#reputation_box').hide();
	$('li#catalogue_toggle').removeClass('off').addClass('on');
	$('li#profile_toggle').removeClass('on').addClass('off');
	$('li#contact_toggle').removeClass('on').addClass('off');
	$('li#map_toggle').removeClass('on').addClass('off');
	$('li#reviews_toggle').removeClass('on').addClass('off');
	$('#sign-in-link').attr('href', '/user/register-login/?returnUrl=' + $.URLEncode(window.location + '#catalogue'));
	$('#join-link').attr('href', '/user/register-login/?returnUrl=' + $.URLEncode(window.location + '#catalogue') + '#reg');
	e.preventDefault();
	window.location.hash = 'reviews';
	return false;
    });

    $('a.sidebodge').live('click',function () {
	$(this).css('color', 'black');
    });

    $("#loginForm").keypress(function(e){
	if (e.which == 13) { 
	    $("#loginSubmit2").click();
	}
    });
	
    $('#upgradeListingLink').click(function(){
	$.get('/supplier/log-upgrade-listing-clicked/format/json/getprofilerecid/'+getProfileRecId, function(data){
	    window.location = $('#upgradeListingLink').attr('href');
	});
	return false;
    });
    $.get('/reviews/supplier-count/s/'+jQuery.url.segment(jQuery.url.segment()-1), function(data) {
	if (parseInt(data)>0)
	{
	    $('#reviewsToggleText').html("Reviews ("+data+")");
				
	}
			
    });
});
