﻿/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupTaobao").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupTaobao").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupTaobao").height();
	var popupWidth = $("#popupTaobao").width();
	//centering
	$("#popupTaobao").css({
		"position": "fixed",
		"top": windowHeight/2-popupHeight/2-25,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$("#popupButton").click(function(){
		
		//transfer taobao link
		$('#taobao_link').val($('#taobao_link_prev').val());
		
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupTaobaoClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});

/////////////////////////////////////////////////

var popupStatus2 = 0;

//loading popup with jQuery magic!
function loadPopup2(){
	//loads popup only if it is disabled
	if(popupStatus2==0){
		$("#backgroundPopup2").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup2").fadeIn("slow");
		$("#popupTaobao2").fadeIn("slow");
		popupStatus2 = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup2(){
	//disables popup only if it is enabled
	if(popupStatus2==1){
		$("#backgroundPopup2").fadeOut("slow");
		$("#popupTaobao2").fadeOut("slow");
		popupStatus2 = 0;
	}
}

//centering popup
function centerPopup2(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupTaobao2").height();
	var popupWidth = $("#popupTaobao2").width();
	//centering
	$("#popupTaobao2").css({
		"position": "fixed",
		"top": windowHeight/2-popupHeight/2-25,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup2").css({
		"height": windowHeight
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$("#popupButton2").click(function(){
		
		//centering with css
		centerPopup2();
		//load popup
		loadPopup2();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupTaobaoClose2").click(function(){
		disablePopup2();
	});
	//Click out event!
	$("#backgroundPopup2").click(function(){
		disablePopup2();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus2==1){
			disablePopup2();
		}
	});

});

///////////////////////////////////////////////////

$(function() {
	
	$('.error').hide();  
	$(".taobao_button").click(function() {
			// validate and process form
			// first hide any error messages
	    $('.error').hide();
			
		var taobao_link = $("input#taobao_link").val();
			if (taobao_link == "") {
	      $("label#taobao_link_error").show();
	      $("input#taobao_link").focus();
	      return false;
	    }
		var taobao_name = $("input#taobao_name").val();
			if (taobao_name == "") {
	      $("label#taobao_name_error").show();
	      $("input#taobao_name").focus();
	      return false;
	    }
		var taobao_price = $("input#taobao_price").val();
			if (taobao_price == "") {
	      $("label#taobao_price_error").show();
	      $("input#taobao_price").focus();
	      return false;
	    }
		var taobao_postage = $("input#taobao_postage").val();
			if (taobao_postage == "") {
	      $("label#taobao_postage_error").show();
	      $("input#taobao_postage").focus();
	      return false;
	    }
		var taobao_qty = $("input#taobao_qty").val();
			if (taobao_qty == "") {
	      $("label#taobao_qty_error").show();
	      $("input#taobao_qty").focus();
	      return false;
	    }
	});
});



$(document).ready(function() {

	//When page loads...
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content

	//On Click Event
	$("ul.tabs li").click(function() {

		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		return false;
	});

});


$(document).ready(function() {
    //Tooltips
	var tip;
	$(".tip_trigger").hover(function(){

		//Caching the tooltip and removing it from container; then appending it to the body
		tip = $(this).find('.tip').remove();
		$('body').append(tip);

		tip.show(); //Show tooltip

	}, function() {

		tip.hide().remove(); //Hide and remove tooltip appended to the body
		$(this).append(tip); //Return the tooltip to its original position

	}).mousemove(function(e) {
	//console.log(e.pageX)
		  var mousex = e.pageX + 20; //Get X coodrinates
		  var mousey = e.pageY + 20; //Get Y coordinates
		  var tipWidth = tip.width(); //Find width of tooltip
		  var tipHeight = tip.height(); //Find height of tooltip

		 //Distance of element from the right edge of viewport
		  var tipVisX = $(window).width() - (mousex + tipWidth);
		  var tipVisY = $(window).height() - (mousey + tipHeight);

		//if ( tipVisX < 20 ) { //If tooltip exceeds the X coordinate of viewport
		//	mousex = e.pageX - tipWidth - 20;
		//	$(this).find('.tip').css({  top: mousey, left: mousex });
		//} if ( tipVisY < 20 ) { //If tooltip exceeds the Y coordinate of viewport
		//	mousey = e.pageY - tipHeight - 20;
		//	tip.css({  top: mousey, left: mousex });
		//} else {
			tip.css({  top: mousey, left: mousex });
		//}
	});
});
