$(document).ready(function() {
	
	$('.tradenettop').live('click',function(e) {
		e.preventDefault();
		openTradeRankPopUp ("tradeRank",this);
	});
	
	$('.tradenet_large_top').live('click',function(e) {
		e.preventDefault();
		openTradeRankPopUp ("tradeRank",this);
	});

	$('.ss-ver-system').live('click',function(e) {
		e.preventDefault();
		openTradeRankPopUp ("verSys",this);
	});

	$('.reviews-popup-link').live('click',function(e) {
		e.preventDefault();
		openTradeRankPopUp ("rev",this);
	});
	/*
	// added by Elvir
	$('.brand-verification-form').live('click',function(e){
		//cancel the link behavior
		e.preventDefault();
		var brandId = $(this).attr("brand_id");
		openBrandInfoCompletionForm(brandId);
		
	});
	*/
	$('span.shipserv_icon').live('click',function(e) {
		//Cancel the link behavior
		e.preventDefault();

		//Get the A tag
		var id = "#membership_tooltip";

		//Set the popup window to center
		$(id).css('top',e.pageY-100);
		$(id).css('left', e.pageX+30);

		//transition effect
		$(id).fadeIn(300);
	});
	
	
	$('.supplier_cell').live('click',function(e) {
		//Cancel the link behavior
		e.preventDefault();

		//Get the A tag
		var id = "#membership_tooltip";

		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();

		//Set heigth and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight});

		//transition effect		
		$('#mask').fadeIn(1000);	
		$('#mask').fadeTo("slow",0.0);	

		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();

		//Set the popup window to center
		$(id).css('top',e.pageY-100);
		$(id).css('left', e.pageX+30);

		//transition effect
		$(id).fadeIn(300);
	});
	
	$('#membership_popup').live('click',function(e) {
		//Cancel the link behavior
		e.preventDefault();

		//Get the A tag
		var id = "#membership_tooltip";

		//Set the popup window to center
		$(id).css('top',e.pageY-100);
		$(id).css('left', e.pageX+30);

		//transition effect
		$(id).fadeIn(300);
	});
	
	$('a.rollover').live('click',function(e) {
		//Cancel the link behavior
		e.preventDefault();

		//Get the A tag
		var id = "#rollover_big";
		var src = $(this).attr('href');

		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();

		//Set heigth and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight});

		//transition effect		
		$('#mask').fadeIn(500);
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();

		//Set the popup window to center
		$(id).css('top',e.pageY-100);
		$(id).css('left', e.pageX+30);

		//transition effect
		$(id).html('<img src="'+src+'" />')
		$(id).fadeIn(300);
	});
	
	$('#resultStats').live('click',function(e) {
		//Cancel the link behavior
		e.preventDefault();

		//Get the A tag
		var id = "#resultStatsModal";

		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();

		//Set heigth and width to mask to fill up the whole screen
		$('#mask3').css({'width':maskWidth,'height':maskHeight});

		//transition effect
		$('#mask3').fadeTo(0,0.5);
		$('#mask3').fadeIn(1000);

		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();

		//Set the popup window to center
		$(id).css('top', (winH - 400) / 2);
		$(id).css('left', (winW - 500) / 2);

		//transition effect
		$(id).fadeIn(300);
	});

	//if close button is clicked
	$('a.close').click(function (e) {
		e.preventDefault();
		$('#mask').hide();
		$('.window').hide();
		$('.window2').hide();
		$('.window3').hide();
	});
	
	//if mask is clicked
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
		$('.window2').hide();
		$('.window3').hide();
		$('#traderankTooltip').hide();

	});

	$('#rollover_big').click(function () {
		$(this).hide();
		$('#mask').hide();
		$('#mask3').hide();
	});

});


function openBrandInfoCompletionForm (brandId)
{
	alert("opening form for brandId: " + brandId);	

	$('.window').hide();

	//Get the A tag
	var id = "#brand_invitation_form_popup";

	if (!$('#mask')){
		bodyEl = $$('body')[0];
		bodyEl.append('<div id="mask"></div>');
	}

	if (!$(id)){
		bodyEl = $$('body')[0];
		bodyEl.append('<div id="traderankTooltip"></div>');
	}

	//Get the screen height and width
	var maskHeight = $(document).height();
	var maskWidth = $(window).width();

	//Set heigth and width to mask to fill up the whole screen
	$('#mask').css({'width':maskWidth,'height':maskHeight});

	//transition effect
	$('#mask').fadeIn(500);
	$('#mask').fadeTo("slow",0.8);

	//Set the popup window to center

	$(id).css("position","absolute");
	$(id).css("top", ( $(window).height() - $(id).height() ) / 2+$(window).scrollTop() + "px");
	$(id).css("left", ( $(window).width() - $(id).width() ) / 2+$(window).scrollLeft() + "px");


	$.get('/supplier/invite-brand-owner-form/brandId/'+brandId, function(data) {
		$(id).html(data);
	});

	//transition effect
	$(id).fadeIn(300);

}
function openTradeRankPopUp (tabIdent,el)
{
		$('.window').hide();

		//Get the A tag
		var id = "#traderankTooltip";

		if (!$('#mask')){
			bodyEl = $$('body')[0];
			bodyEl.append('<div id="mask"></div>');
		}

		if (!$(id)){
			bodyEl = $$('body')[0];
			bodyEl.append('<div id="traderankTooltip"></div>');
		}

		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();

		//Set heigth and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight});

		//transition effect
		$('#mask').fadeIn(500);
		$('#mask').fadeTo("slow",0.8);

		//Set the popup window to center

		$(id).css("position","absolute");
		$(id).css("top", ( $(window).height() - $(id).height() ) / 2+$(window).scrollTop() + "px");
		$(id).css("left", ( $(window).width() - $(id).width() ) / 2+$(window).scrollLeft() + "px");


		var idArray = $(el).attr('id').split('-');
		var tnid = parseInt(idArray[1]);

		$.get('/supplier/traderank-tooltip/tab/'+tabIdent+'/tnid/'+tnid, function(data) {
			$(id).html(data);
		});

		//transition effect
		$(id).fadeIn(300);
}
