// jQuery written for LoveFineArt (c)

// append the prodQuery menu item with a var indicating searchWithin if the checkBox has been checked
$(document).ready(function() {

// See user forgot Pasword section below for functions
//$("#request-new-password-submit").click( function(){ requestNewPaswordFormValidation(); });

$("a.tool-tip").hover(
			    function(){  
			    					$(this).find("div").show(); 
								} , 
				function(){  
									$(this).find("div").hide();  
								} );

// //////////////////////////////////////////////////////////////////////////////
//  TOOL TIP: PRODUCT DETAIL PAGE    
// ////////////////////////////////////////////////////////////////////////////// 
    var numOfRows = $("#num_of_prod_type_rows").html();
    for (row =0; row<=numOfRows; row++) {
			//iterate thru each product type row on the product details page
			
			   $(".prod-info-holder #what-is-this-"+row).tooltip({ 
			   // Slide Effect
			     effect: 'fade',
				// each trashcan image works as a trigger 
				tip: '#tooltip-'+row, 
				// custom positioning 
				position: 'top left', 
				// move tooltip to optimum position
				offset: [-185,-170], 
				// do not initialize tooltips until they are used 
				lazy: true,  
				// there is no delay when the mouse is moved away from the trigger 
				delay: 300 
				});
				
    }
 // /////////////////////////////////////////////////////////////////////      
 //      TABS     
 // /////////////////////////////////////////////////////////////////////  
 			// This will append the current tabs id with "-current"
			$("li").click(function(){
				// TAB (list item) Clicked	
				var clickedTab = this.id;
				// iterate thru the tabs	
				 $("ul.tabs li").each(function(){		
				 // iterate thru the list
								if( this.id == clickedTab ){
								// mark the "clicked" tab as current
									this.id = this.id+"-current";	
								}else{
								// remove current from existing "not click" tab
									this.id = this.id.replace("-current", "" );
								}// if-else
						});  // function
			}); //  $("li").click
	//adding a comment jjs
	
			$(function() { 
				// setup ul.tabs to work as tabs for each div directly under div.box 
				$("ul.tabs").tabs("div.box:hover > div"); 
			});
 // /////////////////////////////////////////////////////////////////////   
 
  // ////////////////////////////////////////////////////////////////////   

// //////////////////////////////////////////////////////////////////////////////////
// //////////////// START:          SEARCH WITHIN     ///////////////////////////
// //////////////////////////////////////////////////////////////////////////////////
// Upon the click of any of the search menu items....
$("#secondary-column ul li a").click(function() {
		// ...check to see if the "seach-within" check box has been checked
		var seachWithin = $("#search-within input").attr("checked");// true or false
		if ( seachWithin == true){
				//... append the GET vars with "&searchWithin=TRUE";
				var origHref = $(this).attr("href");// true or false
				var newHref = origHref+"&searchWithin=TRUE";
				$(this).attr("href", newHref);
				var refNow = $(this).attr("href");
				
			}//if
		});	
// /////////////////////////////////////////////////////////////////////////////////
// ////////////////  END:           SEARCH WITHIN        ////////////////////////
// /////////////////////////////////////////////////////////////////////////////////

		
// ///////////////////////////////////////////////////////////////////////
// START:  CUSTOMER LOG-IN or REGISTER Link Response  //////
// //////////////////////////////////////////////////////////////////////
// Upon the click of the "login"  link ( id="custLoginLink"),
// this function pops open the "attention-div" box and put the a login 
// form inside it as an AJAX call from the "_ajax/customerLogin.php" file.
//---------+---------+---------+---------+---------+---------+---------+---------+
// NOTE: There are functions in _templates/attentionBox_logIn.tmp.php
// It must reside there because as an AJAX call, $(document).ready
// wont work on it from here.
//---------+---------+---------+---------+---------+---------+---------+---------+
$("#custLoginLink").click(
							function() {
							   var destination = $("#custLoginLink").attr("href");// true or false
								attentionBox_logIn(destination);
							}//function
				);
 // ///////////////////////////////////////////////////////////////////////// 
//    END:  CUSTOMER LOG-IN or REGISTER Link Response  
 /////////////////////////////////////////////////////////////////////////// 
 // //////////////////////////////////////////////////////////////////////// 
//   START:  CUSTOMER LOG-OUT                                   
 // //////////////////////////////////////////////////////////////////////// 
// Upon the click of the "log out"  link ( id="custLogOutLink"),
// this function ...
// .
$("#custLogOutLink").click(
				function() {	
							$.post( 
										// beginning slash needed due to modReWrite
										"/_ajax/customerAuthentication.php", 
										{ status: "logout" },
										function(data){ 
												$("#ui_div").html(data);
												}
						);// $post		
					showAttentionBox();
				}//function
		);
// //////////////////////////////////////////////////////////////////////
//    END:  CUSTOMER LOG-IN or REGISTER Link Response  ////// 
/////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////
//   START:  					ADD To CART      ///////
// //////////////////////////////////////////////////////////////////////
$(".add2cart-1").click(function() {	
						var info = this.id.split( "-" );
						var prod_id 	= info[0];
						var cart_row =	 info[1];
						var cpi_id 	=	 info[2];
						var action 	=	 info[3];
						$.post( 
									"/shopping-cart",
									{ prod_id: prod_id },
									function(data){	
										// remove from wish list after adding to cart
										updateWishlistRow(cart_row,cpi_id,prod_id,action);
										var url = "/shopping-cart";    
										$(location).attr('href',url);
									});
	});//$(".add2cart-1").click

$(".add2cart-results").click(function() {	
						var prod_id = this.id;	
						$.post( 
									"/shopping-cart",
									{ prod_id: prod_id },
									function(data){	
										var url = "/shopping-cart";    
										$(location).attr('href',url);
									});
	});//$(".add2cart-1").click
// //////////////////////////////////////////////////////////////////////////////
//    	END:  					ADD TO CART  			  ////// 
////////////////////////////////////////////////////////////////////////////////
// /////////////////////////////////////////////////////////////////////////////////
// //////////////// START:      WISHLIST    ////////////////////////
// /////////////////////////////////////////////////////////////////////////////////

// sr stands for search result(s)
$(".add2wishlist-sr").click(function() {	
						var prod_id = this.id;	
						$.post( 
									"/wishlist",
									{ prod_id: prod_id },
									function(data){	
										var url = "/wishlist";    
										$(location).attr('href',url);
									});
	});//$(".add2wishlist").click
	
$(".add2wishlist").click(function() {	
						var prod_id = this.id;	
						$.post( 
									"/wishlist",
									{ prod_id: prod_id },
									function(data){	
										var url = "/wishlist";    
										$(location).attr('href',url);
									});
	});//$(".add2cart-1").click
	
$(".cart2wishlist").click(function() {	
						var info = this.id.split( "-" );
						var prod_id 	 = info[0];
						var cart_row =	 info[1];
						var cpi_id 	 =	 info[2];
						var action 	 =	 info[3];	// action = "remove"
						$.post( 
									"/wishlist",
									{ prod_id: prod_id },
									function(data){	
										var url = "/wishlist";    
										//Remove from cart after saving to wish list
										updateCartRow(cart_row,cpi_id,prod_id,action);
										var url = "/shopping-cart";    
										$(location).attr('href',url);
									});
	});//$(".cart2wishlist").click
	
	$(".wishlist2cart").click(function() {	
						var info = this.id.split( "-" );
						var prod_id 	 = info[0];
						var cart_row =	 info[1];
						var cpi_id 	 =	 info[2];
						var action 	 =	 info[3];	// action = "remove"
						$.post( 
									"/shopping-cart",
									{ prod_id: prod_id },
									function(data){	 
										//Remove from cart after saving to wish list
										updateWishlistRow(cart_row,cpi_id,prod_id,action);
										var url = "/shopping-cart";    
										$(location).attr('href',url);
									});
						return false;// <-- Keeps page from going to link on its own
									
	});//$(".cart2wishlist").click
	
	
// NOTE: Not sure if this is being used
// no time to check right now so clean this up when you have time
$("#wishListLink").click( function() {
								var isUserLoggedIn	= $("#isUserLoggedIn").attr("value");// true or false
								var destination			= $("#wishListLink").attr("href");// true or false
								if ( isUserLoggedIn == "false" ){
											attentionBox_logIn(destination);
											return false;// <-- Keeps page from going to link on its own
											}// if
							}//function
				);	

// NOTE: Not sure if this is being used
// no time to check right now so clean this up when you have time
$(".add2wishlist-det").click(function() {	
						var prod_id = this.id;	
						alert("ID: "+ prod_id );
						$.post( 
									"/wishlist",
									{ prod_id: prod_id },
									function(data){	
										var url = "/wishlist";    
										$(location).attr('href',url);
									});
	});//$(".add2wishlist").click
	

// ////////////////////////////////////////////////////////////////////////////
//                  NEWSLETTER SIGN UP
// ///////////////////////////////////////////////////////////////////////////// 
$("#btn-newsletter").click(function() {
// on click  validate the email
var email = $("#newsletter-email").val();
var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(email.match(emailExp)){
	            $.post( 
						   "/_ajax/newletter_signups.php",
							{ email: email },
							function(data){
								$("#response").html(data);
								$("#newsletter-email").val('');
								}// function
							);// post
						 
	}else{ 
			   //error message.
			   $("#response").html('<p class="message2 strong">Error: Please type a valid email.</p>');
	}
});

// ////////////////////////////////////////////////////////////////////////////
//                  CONTACT US
// ///////////////////////////////////////////////////////////////////////////// 
$("a#contactus-submit").click(function(){
		var nameF = $("#contactus-name-first");
		var nameL = $("#contactus-name-last");
		var email  = $("#contactus-email");
		var comment  = $("#contactus-comment");
		var valid  = true;
		
		if( ! validateProspName('contactus-name-first') ){
			$("#contactus-name-first-msg").html('&nbsp;&nbsp;Please enter valid name');
			valid  = false;
			}else{   $("#contactus-name-first-msg").val('&nbsp;&nbsp;*'); }
		if( ! validateProspName('contactus-name-last') ){
			$("#contactus-name-last-msg").html('&nbsp;&nbsp;Please enter valid name');
			valid  = false;
			}else{   $("#contactus-name-last-msg").val('&nbsp;&nbsp;*'); }
		if( ! validateProspName('contactus-email') ){
			$("#contactus-email-msg").html('&nbsp;&nbsp;Please enter valid email');
			valid  = false;
			}else{   $("#contactus-email-msg").val('&nbsp;&nbsp;*'); }
		if( valid ) {
		$("#response").html('<h4> IS VALID </h4>');
		// submit
		$.post( 
				      "/_ajax/contact-us-process.php",
					  { email: email, nameF: nameF, nameL: nameL, comment: comment },
					  function(data){
					    $("#response").html(data);
					   }// function
					);// post		
		}
	return false;
});

});	// END: $(document).ready(function()

function attentionBox_logIn( destination ){
// Put the log in code into the Attention Box
	$.post( 
				// beginning slash needed due to modReWrite
					"/_templates/attentionBox_LogIn.tmp.php", 
					{ destination: destination },
					function(data){ 
							$("#ui_div").html(data);
							}
	);// $post					
	showAttentionBox();
}//




 // ////////////////////////////////////////////////////////////////////////////
//                                ATTENTION BOX 
// ///////////////////////////////////////////////////////////////////////////// 
function showAttentionBox(){
	$("#ui_div").addClass("attention-box"); // make attention box visible
	$("#root").addClass("subdue"); // fade the background stuff
}//function

function hideAttentionBox(){ 
// NOTE: This also empties the code from the attention-box
	$("#ui_div").removeClass("attention-box"); // remove - make attention box visible
	$("#root").removeClass("subdue"); // un-fade the background stuff
	$("#ui_div").html('');// Important: Fill the Div with emptyness once you're done.
}//function

$(".attention-box input").focus(function() {
		$(this).addClass("input-focus");
	});
$(".attention-box input").blur(function() {
		$(this).removeClass("input-focus");
	});


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




