// Custom JavaScript / JQuery Operations


function addLoadListener(fn) {
//mozilla and friends
  if (typeof window.addEventListener != 'undefined') {
    window.addEventListener('load', fn, false);
  }
//opera
  else if (typeof document.addEventListener != 'undefined') {
    document.addEventListener('load', fn, false);
  }
//innernetz exploder
  else if (typeof window.attachEvent != 'undefined') {
    window.attachEvent('onload', fn);
  }
//the rest is pretty much for browsers that I doubt your 
//CSS or anything else still supports like IE/Mac
  else {
    var oldfn = window.onload;
    if (typeof window.onload != 'function') {
      window.onload = fn;
    }
    else {
      window.onload = function() {
        oldfn();
        fn();
      };
    }
  }
}

// Navigation Animation

$(function(){ $(".lavaLamp").lavaLamp({fx: "easeinout",speed: 400}); });

// Main Page Social Media Bar

$("#buttonPREV").animate({opacity: 1.0}, 300, "easeinout");
$(document).ready(function(){
	$("#socialMediaBar ol li:first").css('width',250);
	$("#socialMediaBar ol li").hover(function(){
		$("#socialMediaBar ol li").animate({width:50},{queue:false,duration:150});
		$(this).animate({width:250},{queue:false,duration:150});
	});
});

// HOW IT WORKS

$(document).ready(function(){
	$(".coupleINFO").hide();
	$(".guestINFO").hide();
	$(".coupleHOW").click( function(){$(".guestINFO").hide();$(".instructionINFO").hide();$(".coupleINFO").show();});
	$(".guestHOW").click( function(){ $(".coupleINFO").hide();$(".instructionINFO").hide();$(".guestINFO").show();});
});

// Main Page Slider

function sliderPosition(index){
    switch (index) {
        case 0:
            $("#sliderBreadCrumbs ul li:first").css("color", "#000000");
            $("#sliderBreadCrumbs ul li:first").next().css("color", "#999999");
            $("#sliderBreadCrumbs ul li:first").next().next().css("color", "#999999");
            $("#sliderBreadCrumbs ul li:first").next().next().next().css("color", "#999999");
            $("#sliderBreadCrumbs ul li:first").next().next().next().next().css("color", "#999999");
			$("#sliderBreadCrumbs ul li:first").next().next().next().next().next().css("color", "#999999");
            break
        case -1000:
            $("#sliderBreadCrumbs ul li:first").css("color", "#999999");
            $("#sliderBreadCrumbs ul li:first").next().css("color", "#000000");
            $("#sliderBreadCrumbs ul li:first").next().next().css("color", "#999999");
            $("#sliderBreadCrumbs ul li:first").next().next().next().css("color", "#999999");
            $("#sliderBreadCrumbs ul li:first").next().next().next().next().css("color", "#999999");
			$("#sliderBreadCrumbs ul li:first").next().next().next().next().next().css("color", "#999999");
            break
        case -2000:
            $("#sliderBreadCrumbs ul li:first").css("color", "#999999");
            $("#sliderBreadCrumbs ul li:first").next().css("color", "#999999");
            $("#sliderBreadCrumbs ul li:first").next().next().css("color", "#000000");
            $("#sliderBreadCrumbs ul li:first").next().next().next().css("color", "#999999");
            $("#sliderBreadCrumbs ul li:first").next().next().next().next().css("color", "#999999");
			$("#sliderBreadCrumbs ul li:first").next().next().next().next().next().css("color", "#999999");
            break
        case -3000:
            $("#sliderBreadCrumbs ul li:first").css("color", "#999999");
            $("#sliderBreadCrumbs ul li:first").next().css("color", "#999999");
            $("#sliderBreadCrumbs ul li:first").next().next().css("color", "#999999");
            $("#sliderBreadCrumbs ul li:first").next().next().next().css("color", "#000000");
            $("#sliderBreadCrumbs ul li:first").next().next().next().next().css("color", "#999999");
			$("#sliderBreadCrumbs ul li:first").next().next().next().next().next().css("color", "#999999");
            break
        case -4000:
            $("#sliderBreadCrumbs ul li:first").css("color", "#999999");
            $("#sliderBreadCrumbs ul li:first").next().css("color", "#999999");
            $("#sliderBreadCrumbs ul li:first").next().next().css("color", "#999999");
            $("#sliderBreadCrumbs ul li:first").next().next().next().css("color", "#999999");
            $("#sliderBreadCrumbs ul li:first").next().next().next().next().css("color", "#000000");
			$("#sliderBreadCrumbs ul li:first").next().next().next().next().next().css("color", "#999999");
            break
		case -5000:
            $("#sliderBreadCrumbs ul li:first").css("color", "#999999");
            $("#sliderBreadCrumbs ul li:first").next().css("color", "#999999");
            $("#sliderBreadCrumbs ul li:first").next().next().css("color", "#999999");
            $("#sliderBreadCrumbs ul li:first").next().next().next().css("color", "#999999");
            $("#sliderBreadCrumbs ul li:first").next().next().next().next().css("color", "#999999");
			$("#sliderBreadCrumbs ul li:first").next().next().next().next().next().css("color", "#000000");
            break
    }
};

function sliderPositionSet(target){
    switch (target) {
        case 0:
            sliderPositionMove(target);
            break
        case -1000:
            sliderPositionMove(target);
            break
        case -2000:
            sliderPositionMove(target);
            break
        case -3000:
            sliderPositionMove(target);
            break
        case -4000:
            sliderPositionMove(target);
            break
		case -5000:
            sliderPositionMove(target);
            break
    }    
}

function sliderPositionMove(target){
    var curPos = $('#slider ul').css("left");
    curPos = parseInt(curPos);
    
    if (curPos == 0 || curPos == -1000 || curPos == -2000 || curPos == -3000 || curPos == -4000 || curPos == -5000) {
    
        $("#slider ul").animate({
            left: target
        }, 600, "easeinout");
        
        if (target < 0) {
            $("#buttonPREV").css("visibility", "visible");
            $("#buttonPREV").animate({
                opacity: 1.0
            }, 300, "easeinout");
        }
        else 
            if (target == 0) {
                $("#buttonPREV").animate({
                    opacity: 0.0
                }, 300, "easeinout", function(){
                    $("#buttonPREV").css("visibility", "hidden");
                });
            }
        if (target == -5000) 
            $("#buttonNEXT").animate({
                opacity: 0.0
            }, 300, "easeinout", function(){
                $("#buttonNEXT").css("visibility", "hidden");
            });
        else 
            if (target > -5000) {
                $("#buttonNEXT").css("visibility", "visible");
                $("#buttonNEXT").animate({
                    opacity: 1.0
                }, 300, "easeinout");
            }
        
        sliderPosition(target);
        
    }
}

// Initializations

$(function(){
    $("#buttonPREV").css("visibility", "hidden");
    $("#buttonPREV").css("opacity", 0);
    $("#sliderBreadCrumbs ul li:first").css("color", "#000000");
});

// NEXT button

$(function(){
    $("#buttonNEXT").click(function(){
        var curPos = $('#slider ul').css("left");
        curPos = parseInt(curPos);
        
        if (curPos == 0 || curPos == -1000 || curPos == -2000 || curPos == -3000 || curPos == -4000) {
            curPos = curPos - 1000;
            $("#slider ul").animate({
                left: curPos
            }, 600, "easeinout");
            if (curPos < 0) {
                $("#buttonPREV").css("visibility", "visible");
                $("#buttonPREV").animate({
                    opacity: 1.0
                }, 300, "easeinout");
            }
            if (curPos == -5000) 
                $("#buttonNEXT").animate({
                    opacity: 0.0
                }, 300, "easeinout", function(){
                    $("#buttonNEXT").css("visibility", "hidden");
                });
            
            
            sliderPosition(curPos);
        }
        
    });
});

// PREV button

$(function(){
    $("#buttonPREV").click(function(){
        var curPos = $('#slider ul').css("left");
        curPos = parseInt(curPos);
        if (curPos == -1000 || curPos == -2000 || curPos == -3000 || curPos == -4000 || curPos == -5000) {
            curPos = curPos + 1000;
            $("#slider ul").animate({
                left: curPos
            }, 600, "easeinout");
            if (curPos > -5000) {
                $("#buttonNEXT").css("visibility", "visible");
                $("#buttonNEXT").animate({
                    opacity: 1.0
                }, 300, "easeinout");
            }
            if (curPos == 0) 
                $("#buttonPREV").animate({
                    opacity: 0.0
                }, 300, "easeinout", function(){
                    $("#buttonPREV").css("visibility", "hidden");
                });
            
            sliderPosition(curPos);
        }
        
    });
});


$(function(){

    $("#sliderBreadCrumbs ul li:first").click(function(){
        sliderPositionSet(0)
    });
    $("#sliderBreadCrumbs ul li:first").next().click(function(){
        sliderPositionSet(-1000)
    });
    $("#sliderBreadCrumbs ul li:first").next().next().click(function(){
        sliderPositionSet(-2000)
    });
    $("#sliderBreadCrumbs ul li:first").next().next().next().click(function(){
        sliderPositionSet(-3000)
    });
    $("#sliderBreadCrumbs ul li:first").next().next().next().next().click(function(){
        sliderPositionSet(-4000)
    });
	$("#sliderBreadCrumbs ul li:first").next().next().next().next().next().click(function(){
        sliderPositionSet(-5000)
    });
    
});

// HOW IT WORKS - Accordian

// Initialization

$(function(){
    $(".content").hide();
});

$(function(){
    $(".bodyTitle").click(function(){
        $(this).toggleClass("active");
        $(this).next(".content").slideToggle();
        return false;
    });
});

// CREATE - Page 1

$(document).ready(function(){
    $(".maleFemale").mouseover(function(){
        $(this).children().animate({
            opacity: 0.5
        }, 200, "easeinout");
    });
    
    $(".maleFemale").mouseout(function(){
        $(this).children().animate({
            opacity: 0.0
        }, 200, "easeinout");
    });
    
    $(".maleFemale").click(function(){
        if ($(this).next().find("INPUT[type='checkbox']").is(':checked')) {
            $(this).next().find("INPUT[type='checkbox']").attr('checked', false);
            $(this).css("background-position", "0% -100%");
            $(this).children().css("background-position", "0% -100%");
        }
        else {
            $(this).next().find("INPUT[type='checkbox']").attr('checked', true);
            $(this).css("background-position", "0% 0%");
            $(this).children().css("background-position", "0% 0%");
        }
    });
});

// CREATE - Page 2 (GIFT SELECTOR)

$(document).ready(function(){
						   
	$("#giftArea ul li:last").hide('fast');
						   
    $("#giftCategory ul li").click(function(){
		var counter = 0;
        $("#giftCategory ul li").removeClass("selectedCategory");
        $(this).addClass("selectedCategory");

        var category = $(this).children("#catid").text();
		
        if (category == "all") {
            $("#giftArea ul").fadeOut('fast');
            $("#giftArea ul li").show('slow');
            $("#giftArea ul").fadeIn('slow');
			$("#giftArea ul li:last").hide('fast');
        }
        else 
            if (category == "myList") {
                $("#giftArea ul li").each(function(){
                    if ($(this).children(".hidden").find("INPUT[type='checkbox']").is(':checked')) {
                        $(this).show('slow');
						counter += 1;
                    } else if ( "noGift" == $(this).children("#cat_id").text() && counter == 0 ) {
                        $(this).show('slow');
					} else {
                        $(this).hide('slow');
                    }
                });
            }
            else {
                $("#giftArea ul").fadeOut('fast');
                $("#giftArea ul li").each(function(){
					
                    if (category == $(this).children("#cat_id").text()) {
                        $(this).show('slow');
						counter += 1;						
                    } else if ( "noGift" == $(this).children("#cat_id").text() && counter == 0 ) {
                        $(this).show('slow');
					} else {
                        $(this).hide('slow');
                    }
					
					
                });
                $("#giftArea ul").fadeIn('slow');
            }
			
			if ( counter == 0 ){
			}
    });
});

$(document).ready(function(){
    $("#myGiftsButton").click(function(){
		
		$("#giftCategory ul li").removeClass("selectedCategory");
		$("#giftCategory ul li:eq(1)").addClass("selectedCategory");

		$("#giftArea ul li").each(function(){
                    if ($(this).children(".hidden").find("INPUT[type='checkbox']").is(':checked')) {
                    
                        $(this).show('slow');
                    }
                    else {
                        $(this).hide('slow');
                    }
    	});
   });
});

$(document).ready(function(){
	
	$("#removePiece2").click(function(){
		var puzzlePieces = [1, 2, 4, 6, 8, 9, 12];

		var piece_count = jQuery.inArray(parseInt($("#puzzlepieces").val()), puzzlePieces);

		if(piece_count > 1) {
			var item_price = parseFloat(($("#popup_item_price").html()).replace("$", ""));
			var c = piece_count-1;
			$(".puzzlepieces_text").html(puzzlePieces[c]);
			$("#puzzlepieces").val(puzzlePieces[c]);
			
			$("#item_puzzle_price_per_piece").html((item_price / puzzlePieces[c]).toFixed(2));
			$("#item_puzzle_price_per_piece_DISPLAY").html((item_price / puzzlePieces[c]).toFixed(2));
		}
	});
	$("#addPiece2").click(function() {
		var puzzlePieces = [1, 2, 4, 6, 8, 9, 12];
		var piece_count = jQuery.inArray(parseInt($("#puzzlepieces").val()), puzzlePieces);
		
		var max_piece_count = parseInt($("#max_puzzle_pieces").val());
		if(piece_count <= max_piece_count) {
			var c = piece_count+1;
			$(".puzzlepieces_text").html(puzzlePieces[c]);
			$("#puzzlepieces").val(puzzlePieces[c]);
			var item_price = parseFloat(($("#popup_item_price").html()).replace("$", ""));
			$("#item_puzzle_price_per_piece").html((item_price / c).toFixed(2));
			$("#item_puzzle_price_per_piece_DISPLAY").html((item_price / c).toFixed(2));
			
		}
	});
	
	$("#buygift2").click(function(){
		
		var item_id = $("#popup_item_id").val();
		var item = $("#"+item_id);
			
			//			ADDING GIFT TO REGISTRY FROM "ADD" BUTTON
			
			if (parseInt($("#selectCount").val()) > 0) {
				
				$(item).children(".hidden").find("INPUT[type='checkbox']").attr('checked',true);
				$(item).children(".hidden").children("INPUT[type='text']:eq(0)").val(parseInt($("#selectCount").val()));
			
				$("#guestCartTotal").val( ( ((parseFloat($("#guestCartTotal").val()))) + ( (parseFloat($("#selectCount").val())) * ($("#pricePerPiece").val()) ) ) );
		
				$(".guestCartTotalDisplay").html( '$' + (parseFloat($("#guestCartTotal").val())).toFixed(2) );
				
				$("#giftArea ul li").each( function() {
					if ($(this).children(".hidden").find("INPUT[type='checkbox']").is(':checked')) {
									
						if ( $(this).children(".hidden").children(".usedpieces").val() > 0 && $(this).children(".hidden").children(".isGuestView").val() != 1 ) {
							$(this).css("background-color", "#a6ab98");
						} else {
							$(this).css("background-color", "#b5d466");
							
						}
					}
				});
		
				$.modal.close();
		
			} else {
				
				alert( "Please select puzzle pieces first");
				
			}
	});
});

$(document).ready(function(){
	
	$("#removePiece").click(function(){
									 
		var puzzlePieces = [1, 2, 4, 6, 8, 9, 12];

		var piece_count = jQuery.inArray(parseInt($("#puzzlepieces").val()), puzzlePieces);
		
		if(piece_count > 0) {
			var item_price = parseFloat(($("#popup_item_price").html()).replace("$", ""));
			var c = piece_count-1;
			setPuzzleIndex( c );
			$(".puzzlepieces_text").html(puzzlePieces[c]);
			$("#puzzlepieces").val(puzzlePieces[c]);
			
			$("#item_puzzle_price_per_piece").html((item_price / puzzlePieces[c]).toFixed(2));
			$("#item_puzzle_price_per_piece_DISPLAY").html((item_price / puzzlePieces[c]).toFixed(2));
			
		}
		
		if ( piece_count != 1 ) {
			$(".puzzle-block").show();
		} else {
			$(".puzzle-block").hide();
		}
	});
	
	$("#addPiece").click(function() {

		var puzzlePieces = [1, 2, 4, 6, 8, 9, 12];
		var piece_count = jQuery.inArray(parseInt($("#puzzlepieces").val()), puzzlePieces);
		
		if ( piece_count < 0 )
			piece_count = 0;
		
		var max_piece_count = parseInt($("#max_puzzle_pieces").val());
		if(piece_count < 6 ) {
			
			var c = piece_count+1;
			
			setPuzzleIndex( c );
			
			$(".puzzlepieces_text").html(puzzlePieces[c]);
			$("#puzzlepieces").val(puzzlePieces[c]);
			var item_price = parseFloat(($("#popup_item_price").html()).replace("$", ""));
			$("#item_puzzle_price_per_piece").html((item_price / puzzlePieces[c]).toFixed(2));
			$("#item_puzzle_price_per_piece_DISPLAY").html((item_price / puzzlePieces[c]).toFixed(2));
			
		}
	});
	
	$("#buygift").click(function(){
		var item_id = $("#popup_item_id").val();
		
		var item = $("#"+item_id);
		
		if ( $(item).children(".hidden").find("INPUT[type='checkbox']").is(':checked') )
		{
		
			
			$(item).children(".hidden").find("INPUT[type='checkbox']").attr('checked',false);
			$(item).children(".hidden").children("INPUT[type='text']").val(0);
			$(item).children(".hidden").find("#rating").val('');
			$(item).children(".hidden").children(".item_price").html(".popup_item_price").val();
			
			var category = $(".selectedCategory").children().text();
			if(category == "myList") {
				$(item).hide("slow");
			}
			
		} else {
			
			if ( $("#puzzlepieces").val() == 0 )
				$("#puzzlepieces").val(1);
				
			$(item).children(".hidden").find("INPUT[type='checkbox']").attr('checked',true);
			$(item).children(".hidden").children("INPUT[type='text']:eq(0)").val(parseInt($("#puzzlepieces").val()));
			$(item).children(".hidden").children("INPUT[type='text']:eq(1)").val(0);
			
			var rating = $(".ratingGraphicSelected").find("input[type='checkbox']").val();
			
			for(var i = 0; i < rating; i++) {
				$(item).find("#ratingicons").append("<dt></dt>");
			}
			
			$(item).children(".hidden").children("INPUT[type='checkbox']:eq(1)").val(rating);
			
			$(item).addClass("giftSelected");
			
			var totalPiecesInRegistry = parseInt( $("#totalPuzzlePiecesInRegistry").html() );
			$("#totalPuzzlePiecesInRegistry").html(totalPiecesInRegistry + parseInt($("#puzzlepieces").val()));
			
		}
		
		$("#giftArea ul li").each( function() {
			if ($(this).children(".hidden").find("INPUT[type='checkbox']").is(':checked')) {
							
				if ( $(this).children(".hidden").children(".usedpieces").val() > 0 && $(this).children(".hidden").children(".isGuestView").val() != 1 ) {
					$(this).css("background-color", "#a6ab98");
				} else {
					$(this).css("background-color", "#b5d466");
				}
			}
		});
		
		$.modal.close();
		
	});
});

$(document).ready(function(){

	// count all the items that are select..
	
	allItems = $("input[name='item_piece_count[]']");
	var count = 0;
	allItems.each(function(i, x){
	    var x = parseInt($(this).val());
	    if(! isNaN(x)){
	    	count = count + x;
	    }
	
	});
	$("#totalPuzzlePiecesInRegistry").html(count);
	
	$("#giftArea ul li").each( function() {
		if ($(this).children(".hidden").find("INPUT[type='checkbox']").is(':checked')) {
						
			if ( $(this).children(".hidden").children(".usedpieces").val() > 0 && $(this).children(".hidden").children(".isGuestView").val() != 1 ) {
				$(this).css("background-color", "#a6ab98");
			} else {
				$(this).css("background-color", "#b5d466");
			}
		}
	});

    $("#giftArea ul li").hover(function(){
        $(this).css("background", "#ceea87");
        
    }, function(){

		if ($(this).children(".hidden").find("INPUT[type='checkbox']").is(':checked')) {
			if ( $(this).children(".hidden").children(".usedpieces").val() > 0 && $(this).children(".hidden").children(".isGuestView").val() != 1 ) {
			
				$(this).css("background", "#a6ab98");
			} else {
        		$(this).css("background", "#b5d466");
        		
			}
		} else {
			$(this).css("background", "#eee");
			$(this).css("background", "#fff");
		}
    });
    
    $("#giftArea ul li").click(function(){
	
        var item_id = $(this).attr("id");
		var popupitemid = $("#popup_item_id")[0];
        $(popupitemid).val(item_id);
		
		var purchasedPieceCount = $(this).children(".hidden").children(".usedpieces").val();
		var isGuestView = $(this).children(".hidden").children(".isGuestView").val();
        
        var alreadyBought = false;
        if ($(this).children(".hidden").find("INPUT[type='checkbox']").is(':checked')) {
            alreadyBought = true;
        }
        
        if (alreadyBought) {
			if ( purchasedPieceCount > 0 && isGuestView != 1 )
				alert("ERROR: Guests have already purchased a portion of this gift, it cannot be removed.");
			else {
							
				$(this).css('background','#b63c47');
				var answer = confirm  ("Are you sure you want to remove this item?");
				if(answer) {
					$(this).children(".hidden").find("INPUT[type='checkbox']").attr('checked',false);
					$(this).removeClass("giftSelected");
					
					$("#guestCartTotal").val( ( ((parseFloat($("#guestCartTotal").val()))) - ( (parseInt($(this).children(".hidden").children("INPUT[type='text']").val())) * ( ( (parseFloat($(this).children(".itempriceDIV").children("INPUT[type='text']").val())) ) / ( (parseInt($(this).children("INPUT[type='hidden']:first").val())) ) ) ) ) );
		
					$(".guestCartTotalDisplay").html( '$' + (parseFloat($("#guestCartTotal").val())).toFixed(2) );
					
					var p_in_gift = $(this).children(".hidden").children("INPUT[type='text']:first").val();
					$(this).children(".hidden").children("INPUT[type='text']:first").val(0)
					var totalPiecesInRegistry = parseInt( $("#totalPuzzlePiecesInRegistry").html() );
					$("#totalPuzzlePiecesInRegistry").html(totalPiecesInRegistry - parseInt(p_in_gift));
				}
			}
			
        } else {
			
			//location.href='#';
			
			$.modal('<div style="margin: 0px auto; width: 100%; text-align: center; padding-top: 50px; color: red;"><img src="./style/ajax-loader.gif"/></div>',
			{
				closeHTML: "",
				containerCss:{
						backgroundColor:"transparent",
						borderColor:"transparent",
						height:450,
						padding:0,
						width:830
					},
			});
			
			$.post(BASE_URL + "ajax/getitem/" + item_id.replace("item_", ""), 
				function(data){
					
					var item_data = eval("(" + data + ")");
					if (item_data.item_id > 0) {
						$("#puzzlepieces").val(1);
						
						$("#selectCount").val(0);
						$("#popup_item_title").html(item_data.item_name);
						$("#max_puzzle_pieces").val(item_data.item_max_pieces);
						$("#popup_item_price").html("$"+item_data.item_price);
						$("#popup_item_description").html(item_data.item_description);
						$("#item_image").attr("src", BASE_URL + "uploads/" + item_data.item_picture_url);
						
						var num_pieces_count = $("#num_pieces_"+ item_id.replace("item_", ""));
			
						var num_pieces = 1;
						
						if(num_pieces_count) {
							num_pieces = num_pieces_count.val();
							
							// see custom_deleted.js for large portion of code removed from here
							
						}
						$(".puzzlepieces_text").html(num_pieces);
						$(".puzzlepieces_textBuy").html('$0.00');
						
						if ( num_pieces > 1)
						{
							$("#item_puzzle_price_per_piece").html((item_data.item_price / num_pieces).toFixed(2));
							$("#item_puzzle_price_per_piece_DISPLAY").html((item_data.item_price / num_pieces).toFixed(2));
						} else {
							$("#item_puzzle_price_per_piece").html(item_data.item_price);
							$("#item_puzzle_price_per_piece_DISPLAY").html(item_data.item_price);
						}

						if ( num_pieces > 0 )
							$("#pricePerPiece").val((item_data.item_price / num_pieces));
						else
							$("#pricePerPiece").val(item_data.item_price);
						
						var pieceIndex = 0;
						
						if ( num_pieces == 1 )
							pieceIndex = 0;
						else if ( num_pieces == 2 )
							pieceIndex = 1;
						else if ( num_pieces == 4 )
							pieceIndex = 2;
						else if ( num_pieces == 6 )
							pieceIndex = 3;
						else if ( num_pieces == 8 )
							pieceIndex = 4;
						else if ( num_pieces == 9 )
							pieceIndex = 5;
						else if ( num_pieces == 12 )
							pieceIndex = 6;
						
						if ( isGuestView == 1 )
							$("#purchasedPieces").val(purchasedPieceCount);
						else
							$("#purchasedPieces").val(20);

						$("#puzzlepieces").val(pieceIndex);
						
						//$('#popUp').modal();
						$.modal.close();
						
						$('#popUp').modal(
							{
								onOpen: function (dialog) {
									dialog.overlay.fadeIn('fast', function () {
										dialog.data.hide();
										dialog.container.fadeIn('slow', function () {
											dialog.data.slideDown('slow');
										});
									});
								},
								onShow: function() {
									setTimeout("setInitialFlashVariables();", 300);
								}
						});
						
						//setTimeout("setInitialFlashVariables();", 300);
						return false;
					}
				}, "json");			
			
			return false;
		
		}
        
    });   
    
});


$(document).ready(function() {
	if(typeof itemCustomized != "undefined") {
		var item_id = "item_" + itemCustomized + ""; //$(this).attr("id");
		
		$("#popup_item_id").val(item_id);
		
		var popupitemid = $("#popup_item_id")[0];
        $(popupitemid).val(item_id);
		
		var purchasedPieceCount = $(this).children(".hidden").children(".usedpieces").val();
		var isGuestView = $(this).children(".hidden").children(".isGuestView").val();
        
        var alreadyBought = false;
        if ($(this).children(".hidden").find("INPUT[type='checkbox']").is(':checked')) {
            alreadyBought = true;
        }
        
        if (alreadyBought) {
			if ( purchasedPieceCount > 0 && isGuestView != 1 )
				alert("ERROR: Guests have already purchased a portion of this gift, it cannot be removed.");
			else {
							
				$(this).css('background','#b63c47');
				var answer = confirm  ("Are you sure you want to remove this item?");
				if(answer) {
					$(this).children(".hidden").find("INPUT[type='checkbox']").attr('checked',false);
					$(this).removeClass("giftSelected");
					
					$("#guestCartTotal").val( ( ((parseFloat($("#guestCartTotal").val()))) - ( (parseInt($(this).children(".hidden").children("INPUT[type='text']").val())) * ( ( (parseFloat($(this).children(".itempriceDIV").children("INPUT[type='text']").val())) ) / ( (parseInt($(this).children("INPUT[type='hidden']:first").val())) ) ) ) ) );
		
					$(".guestCartTotalDisplay").html( '$' + (parseFloat($("#guestCartTotal").val())).toFixed(2) );
				}
			}
			
        } else {
			
			//location.href='#';
			$.modal('<div style="margin: 0px auto; width: 100%; text-align: center; padding-top: 50px; color: red;"><img src="./style/ajax-loader.gif"/></div>',
			{
				closeHTML: "",
				containerCss:{
						backgroundColor:"transparent",
						borderColor:"transparent",
						height:450,
						padding:0,
						width:830
					},
			});
			
			$.post(BASE_URL + "ajax/getitem/" + item_id.replace("item_", ""), 
				function(data){
					
					var item_data = eval("(" + data + ")");
					if (item_data.item_id > 0) {
						$("#puzzlepieces").val(1);
						
						$("#selectCount").val(0);
						$("#popup_item_title").html(item_data.item_name);
						$("#max_puzzle_pieces").val(item_data.item_max_pieces);
						$("#popup_item_price").html("$"+item_data.item_price);
						$("#popup_item_description").html(item_data.item_description);
						$("#item_image").attr("src", BASE_URL + "uploads/" + item_data.item_picture_url);
						
						var num_pieces_count = $("#num_pieces_"+ item_id.replace("item_", ""));
			
						var num_pieces = 1;
						
						if(num_pieces_count) {
							num_pieces = num_pieces_count.val();
							
							// see custom_deleted.js for large portion of code removed from here
							
						}
						$(".puzzlepieces_text").html(num_pieces);
						$(".puzzlepieces_textBuy").html('$0.00');
						
						if ( num_pieces > 1)
						{
							$("#item_puzzle_price_per_piece").html((item_data.item_price / num_pieces).toFixed(2));
							$("#item_puzzle_price_per_piece_DISPLAY").html((item_data.item_price / num_pieces).toFixed(2));
						} else {
							$("#item_puzzle_price_per_piece").html(item_data.item_price);
							$("#item_puzzle_price_per_piece_DISPLAY").html(item_data.item_price);
						}

						if ( num_pieces > 0 )
							$("#pricePerPiece").val((item_data.item_price / num_pieces));
						else
							$("#pricePerPiece").val(item_data.item_price);
						
						var pieceIndex = 0;
						
						if ( num_pieces == 1 )
							pieceIndex = 0;
						else if ( num_pieces == 2 )
							pieceIndex = 1;
						else if ( num_pieces == 4 )
							pieceIndex = 2;
						else if ( num_pieces == 6 )
							pieceIndex = 3;
						else if ( num_pieces == 8 )
							pieceIndex = 4;
						else if ( num_pieces == 9 )
							pieceIndex = 5;
						else if ( num_pieces == 12 )
							pieceIndex = 6;
						
						if ( isGuestView == 1 )
							$("#purchasedPieces").val(purchasedPieceCount);
						else
							$("#purchasedPieces").val(20);

						$("#puzzlepieces").val(pieceIndex);
						
						//$('#popUp').modal();
						$.modal.close();
						
						$('#popUp').modal(
							{
								onOpen: function (dialog) {
									dialog.overlay.fadeIn('fast', function () {
										dialog.data.hide();
										dialog.container.fadeIn('slow', function () {
											dialog.data.slideDown('slow');
										});
									});
								},
								onShow: function() {
									setTimeout("setInitialFlashVariables();", 300);
								}
						});
						$("#editgift").hide();
						//setTimeout("setInitialFlashVariables();", 300);
						return false;
						
						
					}
				}, "json");			
			
			return false;
		
		}
	}
});

// RATING SELECT METHOD

$(document).ready(function(){
	
	
	$(".rateOne").click(function(){
			if ( $(this).hasClass("ratingGraphicSelected") ) { } else {
					
				$(this).toggleClass("ratingGraphicSelected");
				$(this).find("INPUT[type='checkbox']").attr('checked',true);
				
				$(".rateTwo").removeClass("ratingGraphicSelected");
				$(".rateTwo").find("INPUT[type='checkbox']").attr('checked',false);
				
				$(".rateThree").removeClass("ratingGraphicSelected");
				$(".rateThree").find("INPUT[type='checkbox']").attr('checked',false);
			}
	 });

	$(".rateTwo").click(function(){
			if ( $(this).hasClass("ratingGraphicSelected") ) { } else {
				$(this).toggleClass("ratingGraphicSelected");
				$(this).find("INPUT[type='checkbox']").attr('checked',true);
				
				$(".rateOne").removeClass("ratingGraphicSelected");
				$(".rateOne").find("INPUT[type='checkbox']").attr('checked',false);
				
				$(".rateThree").removeClass("ratingGraphicSelected");
				$(".rateThree").find("INPUT[type='checkbox']").attr('checked',false);
			}
	 });
	
	$(".rateThree").click(function(){
				if ( $(this).hasClass("ratingGraphicSelected") ) { } else {
				$(this).toggleClass("ratingGraphicSelected");
				$(this).find("INPUT[type='checkbox']").attr('checked',true);
				
				$(".rateOne").removeClass("ratingGraphicSelected");
				$(".rateOne").find("INPUT[type='checkbox']").attr('checked',false);
				
				$(".rateTwo").removeClass("ratingGraphicSelected");
				$(".rateTwo").find("INPUT[type='checkbox']").attr('checked',false);
			}
	 });
});

$(function() { 
     $(".howHover").hover( 
          function() { $(".howHoverResult").show(); }, 
          function() { $(".howHoverResult").hide(); } 
     ); 
});

$(function() { 
     $(".heartHover").hover( 
          function() { $(".heartHoverResult").show(); }, 
          function() { $(".heartHoverResult").hide(); } 
     ); 
});