
//////////////////////////////////////////////////////////////////
//																//
// DISABLE CLICK												//
//																//
//////////////////////////////////////////////////////////////////

function disableClick ()
{
	if (document.layers)
		{
		document.captureEvents(Event.MOUSEDOWN);
		document.onmousedown=clickNS4;
		}
	else if (document.all && !document.getElementById)
		{
		document.onmousedown=clickIE4;
		}
	
	document.oncontextmenu=new Function("alert('Function Disabled!');return false");
}

function clickIE4()
{
	if (event.button==2)
		{
		alert("Function Disabled!");
		return false;
		}
}
 
function clickNS4(e)
{
	if (document.layers||document.getElementById&&!document.all)
		{
		if (e.which==2||e.which==3)
			{
			alert("Function Disabled!");
			return false;
			}
		}
}

//////////////////////////////////////////////////////////////////
//																//
// NAVIGATION FUNCTIONS											//
//																//
//////////////////////////////////////////////////////////////////

function navFunctions()
{
	$('.show-education').hover(	function() { $('.show-education span').fadeIn("fast"); }, function() { $('.show-education span').fadeOut("fast"); });
	$('.show-jewellery').hover( function() { $('.show-jewellery span').fadeIn("fast"); }, function() { $('.show-jewellery span').fadeOut("fast"); });
	$('.show-diamond-rings').hover( function() { $('.show-diamond-rings span').fadeIn("fast"); }, function() { $('.show-diamond-rings span').fadeOut("fast"); });
	$('.show-wedding-rings').hover( function() { $('.show-wedding-rings span').fadeIn("fast"); }, function() { $('.show-wedding-rings span').fadeOut("fast"); });
}

//////////////////////////////////////////////////////////////////
//																//
// FRONTPAGE FUNCTIONS											//
//																//
//////////////////////////////////////////////////////////////////

function frontPage()
{
	// BANNER - SET VARIABLES
	banner_total = 0;
    banner_current = 0;
    
    // BANNER - GET INFO
    $('.front-banner-circles').each(function() { if ($(this).hasClass('selected')) { banner_current = $(this).attr("ref"); } banner_total += 1; });
	
	// BANNER - SHOW NEXT/PREV
    $(".front-banner-circles a").click(function() {
        if ($(this).attr("ref") != banner_current)
            {            
            // DO ANIMATION
            $(".front-banner-item:eq(" + $(this).attr("ref") + ")").css("right", "-934px").css("display", "").animate({"right": "0"},{queue:false,duration:500});
            $(".front-banner-item:eq(" + banner_current + ")").css("right", "0").animate({"right": "934px"},{queue:false,duration:500});
            
            // UPDATE CIRCLES
            $(".front-banner-circles a:eq(" + banner_current + ")").removeClass("selected");
            $(".front-banner-circles a:eq(" + $(this).attr("ref") + ")").addClass("selected");
            
			// UPDATE CURRENT BANNER
            banner_current = $(this).attr("ref");
            }
    });
	
	// POPULAR PRODUCT - SHOW NEXT 
	$(".popular-products.next").live("click", function(){
		$.get("/ajax/calls-frontpage.php", { action: "popular-product-next", current_id: $(this).attr("rel"), time: Math.random() }, function(data){ $(".popular-product").html(data); });
	});
	
	// POPULAR PRODUCT - SHOW PREV
	$(".popular-products.prev").live("click", function(){
		$.get("/ajax/calls-frontpage.php", { action: "popular-product-prev", current_id: $(this).attr("rel"), time: Math.random() }, function(data){ $(".popular-product").html(data); });
	});
	
	// TESTIMONIAL - SHOW NEXT 
	$(".testimonials.next").live("click", function(){
		$.get("/ajax/calls-frontpage.php", { action: "testimonial-next", current_id: $(this).attr("rel"), time: Math.random() }, function(data){ $(".testimonial").html(data); });
	});
	
	// TESTIMONIAL - SHOW PREV
	$(".testimonials.prev").live("click", function(){
		$.get("/ajax/calls-frontpage.php", { action: "testimonial-prev", current_id: $(this).attr("rel"), time: Math.random() }, function(data){ $(".testimonial").html(data); });
	});
	
	// VIDEO POPUP
	$(".video-link").live("click", function(){
		$.get("/ajax/front-video.php", { time: Math.random() }, function(data){ $("#video-bg").fadeIn('slow'); $("#video-box").html(data); $("#video-box").fadeIn('slow'); });
	});
	
	// VIDEO POPUP - CLOSE
	$("#video-link, #video-bg").live("click", function(){
		$("#video-box").hide();
		$("#video-box").html('');
		$("#video-bg").hide();
	});
}

//////////////////////////////////////////////////////////////////
//																//
// ENQUIRIES FUNCTIONS											//
//																//
//////////////////////////////////////////////////////////////////

function enquiriesFunctions ()
{
	// ENQUIRY - OPEN POPUP
	$(".header-contact-link").live("click", function(){
		$.get("/ajax/contact.php", { time: Math.random() }, function(data){ $("#contact-bg").fadeIn('slow'); $("#contact-box").html(data); $("#contact-box").fadeIn('slow'); });
	});
	
	// ENQUIRY - OPEN POPUP - LOOSE DIAMONDS
	$(".enquire").live("click", function(){
		$.get("/ajax/contact.php", { action: "loose-diamond", id: $(this).attr("rel"), time: Math.random() }, function(data){ $("#contact-bg").fadeIn('slow'); $("#contact-box").html(data); $("#contact-box").fadeIn('slow'); });
	});
	
	// ENQUIRY - OPEN POPUP - PRODUCT
	$(".product-link-enquire").live("click", function(){
		query = "?id=" + $(this).attr("rel");
		if($(".diamond-id").val()!="")
		{
			query = query + "&diamond_id=" + $(".diamond-id").val();
		}
			
		$('.product-options').each(function(i){ query = query + "&product_options[]=" + $(this).val(); });
		
		$.get("/ajax/contact.php" + query, { action: "product", time: Math.random() }, function(data){ $("#contact-bg").fadeIn('slow'); $("#contact-box").html(data); $("#contact-box").fadeIn('slow'); });
	});
	
	// ENQUIRY - OPEN POPUP - CART
	$(".cart-enquire").live("click", function(){
		$.get("/ajax/contact.php", { action: "cart", time: Math.random() }, function(data){ $("#contact-bg").fadeIn('slow'); $("#contact-box").html(data); $("#contact-box").fadeIn('slow'); });
	});
	
	// ENQUIRY - CLOSE POPUP
	$("#contact-link, #contact-bg").live("click", function(){
		$("#contact-box").hide();
		$("#contact-box").html('');
		$("#contact-bg").hide();
	});
	
	// ENQUIRY - SUBMIT
	$("#contact-form-submit").live("click", function(){
		form_error = false;
		
		// VALIDATE
		if (!$(".contact-form-first-name").val()) { $(".contact-form-first-name").css("border", "1px solid #70198B"); form_error = true; } else { $(".contact-form-first-name").css("border", "1px solid #abadb3"); }
		if (!$(".contact-form-last-name").val()) { $(".contact-form-last-name").css("border", "1px solid #70198B"); form_error = true; } else { $(".contact-form-last-name").css("border", "1px solid #abadb3"); }
		if (!$(".contact-form-email").val()) { $(".contact-form-email").css("border", "1px solid #70198B"); form_error = true; } else { $(".contact-form-email").css("border", "1px solid #abadb3"); }
		if (!$(".contact-form-phone").val()) { $(".contact-form-phone").css("border", "1px solid #70198B"); form_error = true; } else { $(".contact-form-phone").css("border", "1px solid #abadb3"); }
		if (!$(".contact-form-message").val()) { $(".contact-form-message").css("border", "1px solid #70198B"); form_error = true; } else { $(".contact-form-message").css("border", "1px solid #abadb3"); }
		
		// LOAD DIAMOND / PRODUCT INFO
		query =  "?product_id=" + $(".contact-form-product-id").val();
		$('.product-options').each(function(i){ query = query + "&product_options[]=" + $(this).val(); });
		query = query + "&diamond_id=" + $(".contact-form-diamond-id").val();
		query = query + "&include_cart=" + $(".contact-form-cart").val();
		
		// SUBMIT
		if (!form_error)
			$.get("/ajax/contact.php" + query, { action: "submitted", first_name: $(".contact-form-first-name").val(), last_name: $(".contact-form-last-name").val(), email: $(".contact-form-email").val(), phone: $(".contact-form-phone").val(), message: php_encode($(".contact-form-message").val()), time: Math.random() }, function(data){ $("#contact-box").hide(); $("#contact-box").html(''); $("#contact-bg").hide(); alert("Your message has been sent."); });
		else
			alert('Errors were found. Please correct.');
	});
}

//////////////////////////////////////////////////////////////////
//																//
// CHECKOUT FUNCTIONS											//
//																//
//////////////////////////////////////////////////////////////////

function checkoutFunctions()
{
	// CART - DELETE ITEM
	$("a.cart-item-del").live("click", function(){
		ident = $(this).attr("rel");
		$.get("/ajax/calls-cart.php", { action: "del-item", ident: ident, time: Math.random() }, function(data){
			data1 = data.split("|"); 
			
			$("#" + ident).fadeOut(function() {
				if (Number(data1[0]) == 0)
					{
					$(".cart-table-no-results").fadeIn();
					$("#cart-button").attr('disabled', 'disabled');
					}
				
				$(".itemstotal").html(Number(data1[1]));
				
				if (data1[2] == 1)
					$("#cart-continue").attr("disabled", "disabled");
 			});
		});
	});
	
	$("a.cart-item-title").live("click", function(){
	 	id = $(this).attr("rel");
		
		// OPEN POPUP
		if(id > 10000)
		{
	 		$("#dialog-view").dialog({ width: 820, minHeight: 700, modal: true, draggable: false, resizable: false, dialogClass: 'view-dialog', open: function() { $("#dialog-view").load("/ajax/cart-diamond-view.php?id=" + id);}} );
		}
		else
		{
			$("#dialog-view").dialog({ width: 900, minHeight: 550, modal: true, draggable: false, resizable: false, dialogClass: 'view-dialog', open: function() { $("#dialog-view").load("/ajax/cart-ring-view.php?id=" + id);}} );
		}
		
		// CLOSE POPUP
		$('.ui-widget-overlay').live("click", function() { $("#dialog-view").dialog("close"); $("#dialog-view").html(""); });   
		$('.close-dialog').live("click", function() { $("#dialog-view").dialog("close"); $("#dialog-view").html(""); });   
	 } );
	
	// CART - CHANGE QUANITY
	$(".cart-input-qty").live("keyup", function(){
		ident = $(this).attr("rel");
		$(this).val($(this).val().substr(0, 2).replace(/([^0-9])/g, ""));
		
		$.get("/ajax/calls-cart.php", { action: "update-item", ident: ident, qty: $(this).attr("value"), time: Math.random() }, function(data){
			data2 = data.split("|"); 
			
			$("." + ident + "-total").html(data2[0]);
			$(".itemstotal").html(data2[1]);
		});
	});
	
	// CHECKOUT - ENABLE/DISABLE BILLING ADDRESS
	$(".checkout-use-billing").live("click", function(){
		if ($(".checkout-use-billing:checked").val() == "Y") {
			$(".checkout-delivery-first-name, .checkout-delivery-last-name, .checkout-delivery-street-address, .checkout-delivery-suburb, .checkout-delivery-city, .checkout-delivery-state, .checkout-delivery-zip, .checkout-delivery-country").val('').css("border", "1px solid #CCCCCC").attr("disabled", true);
		} else {
			$(".checkout-delivery-first-name, .checkout-delivery-last-name, .checkout-delivery-street-address, .checkout-delivery-suburb, .checkout-delivery-city, .checkout-delivery-state, .checkout-delivery-zip, .checkout-delivery-country").val('').attr("disabled", false);
		}
	});
	
	// CHECKOUT - SUBMIT STEP 1
	$("#checkout-button").live("click", function(){
		form_error = false;
		
		// VALIDATE BILLING
		if (!$(".checkout-first-name").val()) { $(".checkout-first-name").css("border", "1px solid #70198B"); form_error = true; } else { $(".checkout-first-name").css("border", "1px solid #CCCCCC"); }
		if (!$(".checkout-last-name").val()) { $(".checkout-last-name").css("border", "1px solid #70198B"); form_error = true; } else { $(".checkout-last-name").css("border", "1px solid #CCCCCC"); }
		if (!$(".checkout-email").val()) { $(".checkout-email").css("border", "1px solid #70198B"); form_error = true; } else { $(".checkout-email").css("border", "1px solid #CCCCCC"); }
		if (!$(".checkout-phone").val()) { $(".checkout-phone").css("border", "1px solid #70198B"); form_error = true; } else { $(".checkout-phone").css("border", "1px solid #CCCCCC"); }
		if (!$(".checkout-street-address").val()) { $(".checkout-street-address").css("border", "1px solid #70198B"); form_error = true; } else { $(".checkout-street-address").css("border", "1px solid #CCCCCC"); }
		if (!$(".checkout-suburb").val()) { $(".checkout-suburb").css("border", "1px solid #70198B"); form_error = true; } else { $(".checkout-suburb").css("border", "1px solid #CCCCCC"); }
		if (!$(".checkout-city").val()) { $(".checkout-city").css("border", "1px solid #70198B"); form_error = true; } else { $(".checkout-city").css("border", "1px solid #CCCCCC"); }
		if (!$(".checkout-state").val()) { $(".checkout-state").css("border", "1px solid #70198B"); form_error = true; } else { $(".checkout-state").css("border", "1px solid #CCCCCC"); }
		if (!$(".checkout-zip").val()) { $(".checkout-zip").css("border", "1px solid #70198B"); form_error = true; } else { $(".checkout-zip").css("border", "1px solid #CCCCCC"); }
		if (!$(".checkout-country").val()) { $(".checkout-country").css("border", "1px solid #70198B"); form_error = true; } else { $(".checkout-country").css("border", "1px solid #CCCCCC"); }
		
		// VALIDATE DELIVERY
		if ($(".checkout-use-billing:checked").val() != "Y")
			{
			if (!$(".checkout-delivery-first-name").val()) { $(".checkout-delivery-first-name").css("border", "1px solid #70198B"); form_error = true; } else { $(".checkout-delivery-first-name").css("border", "1px solid #CCCCCC"); }
			if (!$(".checkout-delivery-last-name").val()) { $(".checkout-delivery-last-name").css("border", "1px solid #70198B"); form_error = true; } else { $(".checkout-delivery-last-name").css("border", "1px solid #CCCCCC"); }
			if (!$(".checkout-delivery-street-address").val()) { $(".checkout-delivery-street-address").css("border", "1px solid #70198B"); form_error = true; } else { $(".checkout-delivery-street-address").css("border", "1px solid #CCCCCC"); }
			if (!$(".checkout-delivery-suburb").val()) { $(".checkout-delivery-suburb").css("border", "1px solid #70198B"); form_error = true; } else { $(".checkout-delivery-suburb").css("border", "1px solid #CCCCCC"); }
			if (!$(".checkout-delivery-city").val()) { $(".checkout-delivery-city").css("border", "1px solid #70198B"); form_error = true; } else { $(".checkout-delivery-city").css("border", "1px solid #CCCCCC"); }
			if (!$(".checkout-delivery-state").val()) { $(".checkout-delivery-state").css("border", "1px solid #70198B"); form_error = true; } else { $(".checkout-delivery-state").css("border", "1px solid #CCCCCC"); }
			if (!$(".checkout-delivery-zip").val()) { $(".checkout-delivery-zip").css("border", "1px solid #70198B"); form_error = true; } else { $(".checkout-delivery-zip").css("border", "1px solid #CCCCCC"); }
			if (!$(".checkout-delivery-country").val()) { $(".checkout-delivery-country").css("border", "1px solid #70198B"); form_error = true; } else { $(".checkout-delivery-country").css("border", "1px solid #CCCCCC"); }
			}
		
		if (!$(".checkout-payment-method:checked").val()) { $(".checkout-payment-method-error").css("border", "1px solid #70198B"); form_error = true; } else { $(".checkout-payment-method-error").css("border", "1px solid #CCCCCC"); }
		
		if (!form_error)
			{
			query = "?id=" + $(this).attr("rel");
			
			$('.product-options').each(function(i){ query = query + "&product_options[]=" + $(this).val(); });

			$.get("/ajax/calls-checkout.php" + query, { action: "checkout-step1", first_name: $(".checkout-first-name").val(), last_name: $(".checkout-last-name").val(), email: $(".checkout-email").val(), phone: $(".checkout-phone").val(), street_address: $(".checkout-street-address").val(), suburb: $(".checkout-suburb").val(), city: $(".checkout-city").val(), state: $(".checkout-state").val(), zip: $(".checkout-zip").val(), country: $(".checkout-country").val(), use_billing: $(".checkout-use-billing:checked").val(),delivery_first_name: $(".checkout-delivery-first-name").val(), delivery_last_name: $(".checkout-delivery-last-name").val(), delivery_street_address: $(".checkout-delivery-street-address").val(), delivery_suburb: $(".checkout-delivery-suburb").val(), delivery_city: $(".checkout-delivery-city").val(), delivery_state: $(".checkout-delivery-state").val(), delivery_zip: $(".checkout-delivery-zip").val(), delivery_country: $(".checkout-delivery-country").val(), payment_method: $(".checkout-payment-method:checked").val(), time: Math.random() }, function(data){ 
				document.location = "/checkout1.html";
			});
			}
		else
			alert('Errors were found. Please correct.');
	});
	
	// CHECKOUT - SUBMIT STEP 2
	$("#checkout1-button").live("click", function(){
		document.location = "/checkout2.html?action=checkout-complete";
	});
}

//////////////////////////////////////////////////////////////////
//																//
// LOOSE DIAMOND FUNCTIONS										//
//																//
//////////////////////////////////////////////////////////////////

function looseDiamondFunctions ()
{
	// FILTERS - SET VARIABLES
    var shape_binary = 10000000000;
	
	max_price = 100000;
	url = window.location.host.split(".");
	switch(url[url.length - 1])
	{
		case "nz":
		case "au":
		case "ca":
			max_price = 150000;
			break;
		case "cn":
			max_price = 700000;
			break;
		case "jp":
			max_price = 10000000;
			break;
		case "za":
			max_price = 1000000;
			break;
		case "in":
		case "za":
			max_price = 5000000;
			break;
		case "us":
		case "uk":
		case "it":
		case "es":
		case "de":
		case "fr":
			max_price = 100000;
			break;
	}
	
    // FILTERS - CONFIGURE SLIDERS
    $("#slider-range-price").slider({ range: true, min: 0, max: max_price, step: 10, values: [1, max_price], slide: function( event, ui ) { $(".slider-value-price1").val(ui.values[0]); $(".slider-value-price2").val(ui.values[1]); }, stop: function(event, ui) { $(".slider-value-price1").val(ui.values[0]); $(".slider-value-price2").val(ui.values[1]); oTable.fnDraw(); } });
    $("#slider-range-color").slider({ range: true, min: 0, max: 7, values: [0, 7], slide: function( event, ui ) { $(".slider-value-color1").val(ui.values[0]); $(".slider-value-color2").val(ui.values[1]); }, stop: function(event, ui) { $(".slider-value-color1").val(ui.values[0]); $(".slider-value-color2").val(ui.values[1]); oTable.fnDraw(); } });
    $("#slider-range-carat").slider({ range: true, min: 0, max: 5, step: 0.01, values: [0, 5], slide: function( event, ui ) { $(".slider-value-carat1").val(ui.values[0]); $(".slider-value-carat2").val(ui.values[1]); }, stop: function(event, ui) { $(".slider-value-carat1").val(ui.values[0]); $(".slider-value-carat2").val(ui.values[1]); oTable.fnDraw(); } });
    $("#slider-range-clarity").slider({ range: true, min: 0, max: 7, values: [0, 7], slide: function( event, ui ) { $(".slider-value-clarity1").val(ui.values[0]); $(".slider-value-clarity2").val(ui.values[1]); }, stop: function(event, ui) { $(".slider-value-clarity1").val(ui.values[0]); $(".slider-value-clarity2").val(ui.values[1]); oTable.fnDraw(); } });
    
    // FILTERS - SET SLIDER POSITIONS 
    $(".slider-value-price1").val($("#slider-range-price").slider("values", 0));
    $(".slider-value-price2").val($("#slider-range-price").slider("values", 1));
    $(".slider-value-color1").val($("#slider-range-color").slider("values", 0));
    $(".slider-value-color2").val($("#slider-range-color").slider("values", 1));
    $(".slider-value-carat1").val($("#slider-range-carat").slider("values", 0));
    $(".slider-value-carat2").val($("#slider-range-carat").slider("values", 1));
    $(".slider-value-clarity1").val($("#slider-range-clarity").slider("values", 0));
    $(".slider-value-clarity2").val($("#slider-range-clarity").slider("values", 1));
    
    // FILTERS - CLICKABLE COLOR
	$(".color-link").click (function () {
		selectedValue = parseInt($(this).attr("rel"));
		selectedValue1 = parseInt($(this).attr("rel"))+1;
		
		$("#slider-range-color").slider("values", 0, selectedValue);
		$("#slider-range-color").slider("values", 1, selectedValue1);
		
		$(".slider-value-color1").val($("#slider-range-color").slider("values", 0));
    	$(".slider-value-color2").val($("#slider-range-color").slider("values", 1));
		
		oTable.fnDraw();
	} );
	
    // FILTERS - CLICKABLE CLARITY
	$(".clarity-link").click (function () {
		selectedValue = parseInt($(this).attr("rel"));
		selectedValue1 = parseInt($(this).attr("rel"))+1;
		
		$("#slider-range-clarity").slider("values", 0, selectedValue);
		$("#slider-range-clarity").slider("values", 1, selectedValue1);
		
		$(".slider-value-clarity1").val($("#slider-range-clarity").slider("values", 0));
		$(".slider-value-clarity2").val($("#slider-range-clarity").slider("values", 1));
		
		oTable.fnDraw();
	} );
	
	$(".help-link").click (function () {
		rel = $(this).attr("rel");
		
		// OPEN POPUP
	 	$("#dialog-view").dialog({ minHeight: 220, width: 320, modal: true, draggable: false, resizable: false, dialogClass: 'view-dialog', open: function() { $("#dialog-view").load("/ajax/loose-diamonds-help.php?rel=" + rel);}} );
		
		// CLOSE POPUP
		$('.ui-widget-overlay').live("click", function() { $("#dialog-view").dialog("close"); });   
		$('.close-dialog').live("click", function() { $("#dialog-view").dialog("close"); });   
	} );
	
    // LOOSE DIAMONDS - CONFIGURE TABLE
    var oTable = $('#table-loose-diamonds').dataTable( {
		"aaSorting": [[6,'asc']],
        "aoColumns": [ 
            null,
            null,
            null,
            null,
            null,
            { "bSortable": false },
            null,
            { "bSortable": false, "sClass": 'center' }
            ],
		"bInfo": false,
        "bFilter": false,
        "bLengthChange": false,
        "bProcessing": true,
        "bServerSide": true,
        "iDisplayLength": 50,
        "sPaginationType": "full_numbers",
        "sAjaxSource": "/ajax/loose-diamonds.php",
        "fnServerData": function ( sSource, aoData, fnCallback ) {
            /* Add some extra data to the sender */
            aoData.push(
                        { "name": "shape_binary", "value": shape_binary }, 
                        { "name": "price1", "value": $(".slider-value-price1").val() }, 
                        { "name": "price2", "value": $(".slider-value-price2").val() },
                        { "name": "color1", "value": $(".slider-value-color1").val() }, 
                        { "name": "color2", "value": $(".slider-value-color2").val() },
                        { "name": "carat1", "value": $(".slider-value-carat1").val() }, 
                        { "name": "carat2", "value": $(".slider-value-carat2").val() },
                        { "name": "clarity1", "value": $(".slider-value-clarity1").val() },
                        { "name": "clarity2", "value": $(".slider-value-clarity2").val() }
                        );

            $.getJSON( sSource, aoData, function (json) { 
                /* Do whatever additional processing you want on the callback, then tell DataTables */
				//if no results are returned display message.
				document.getElementById("noresults").style.display = 'none';
				if(json['iTotalRecords'] == 1){
					json['aaData'][0] = ['','','','','','','',''];
					document.getElementById("noresults").style.display = 'block';
				}
				
				fnCallback(json)
            } );
			
        }
    } );
	
	
    // LOOSE DIAMONDS - CONFIGURE TABLE
    var oTableFavorites = $('#table-loose-diamonds-favorites').dataTable( {
        "aoColumns": [ 
            null,
            null,
            null,
            null,
            null,
            { "bSortable": false },
            null,
            { "bSortable": false, "sClass": 'center' }
            ],
		"oLanguage": { "sZeroRecords": "Click Compare to populate this table." },
		"bInfo": false,
        "bFilter": false,
        "bLengthChange": false,
        "bProcessing": true,
        "bServerSide": true,
        "bPaginate": false,
        "sAjaxSource": "/ajax/loose-diamonds-favorites.php"
    } );
	
    // TABLE - HANDLE TEXT VALUES
    $(".slider-value-price1").change(function () { if (!isNaN($(".slider-value-price1").val())) { $("#slider-range-price").slider("values", 0, $(".slider-value-price1").val()); oTable.fnDraw(); } else { alert ("The value must be a number"); } });
    $(".slider-value-price2").change(function () { if (!isNaN($(".slider-value-price2").val())) { $("#slider-range-price").slider("values", 1, $(".slider-value-price2").val()); oTable.fnDraw(); } else { alert ("The value must be a number"); } });
    $(".slider-value-carat1").change(function () { if (!isNaN($(".slider-value-carat1").val())) { $("#slider-range-carat").slider("values", 0, $(".slider-value-carat1").val()); oTable.fnDraw(); } else { alert ("The value must be a number"); } });
    $(".slider-value-carat2").change(function () { if (!isNaN($(".slider-value-carat2").val())) { $("#slider-range-carat").slider("values", 1, $(".slider-value-carat2").val()); oTable.fnDraw(); } else { alert ("The value must be a number"); } });
    
    // TABLE - SET SHAPE VARIABLE
     $(".round").click (function () { if ($(this).hasClass("round-active")) { $(this).removeClass("round-active"); shape_binary -= 1; oTable.fnDraw(); } else { $(this).addClass("round-active"); shape_binary += 1; oTable.fnDraw(); } } );
     $(".princess").click (function () { if ($(this).hasClass("princess-active")) { $(this).removeClass("princess-active"); shape_binary -= 10; oTable.fnDraw(); } else { $(this).addClass("princess-active"); shape_binary += 10; oTable.fnDraw(); } } );
     $(".emerald").click (function () { if ($(this).hasClass("emerald-active")) { $(this).removeClass("emerald-active"); shape_binary -= 100; oTable.fnDraw(); } else { $(this).addClass("emerald-active"); shape_binary += 100; oTable.fnDraw(); } } );
     $(".asscher").click (function () { if ($(this).hasClass("asscher-active")) { $(this).removeClass("asscher-active"); shape_binary -= 1000; oTable.fnDraw(); } else { $(this).addClass("asscher-active"); shape_binary += 1000; oTable.fnDraw(); } } );
     $(".cushion").click (function () { if ($(this).hasClass("cushion-active")) { $(this).removeClass("cushion-active"); shape_binary -= 10000; oTable.fnDraw(); } else { $(this).addClass("cushion-active"); shape_binary += 10000; oTable.fnDraw(); } } );
     $(".radiant").click (function () { if ($(this).hasClass("radiant-active")) { $(this).removeClass("radiant-active"); shape_binary -= 100000; oTable.fnDraw(); } else { $(this).addClass("radiant-active"); shape_binary += 100000; oTable.fnDraw(); } } );
     $(".oval").click (function () { if ($(this).hasClass("oval-active")) { $(this).removeClass("oval-active"); shape_binary -= 1000000; oTable.fnDraw(); } else { $(this).addClass("oval-active"); shape_binary += 1000000; oTable.fnDraw(); } } );
     $(".marquise").click (function () { if ($(this).hasClass("marquise-active")) { $(this).removeClass("marquise-active"); shape_binary -= 10000000; oTable.fnDraw(); } else { $(this).addClass("marquise-active"); shape_binary += 10000000; oTable.fnDraw(); } } );
     $(".pear").click (function () { if ($(this).hasClass("pear-active")) { $(this).removeClass("pear-active"); shape_binary -= 100000000; oTable.fnDraw(); } else { $(this).addClass("pear-active"); shape_binary += 100000000; oTable.fnDraw(); } } );
     $(".heart").click (function () { if ($(this).hasClass("heart-active")) { $(this).removeClass("heart-active"); shape_binary -= 1000000000; oTable.fnDraw(); } else { $(this).addClass("heart-active"); shape_binary += 1000000000; oTable.fnDraw(); } } );
	 
	 $(".round-not-in-shapes, .princess-not-in-shapes, .emerald-not-in-shapes, .asscher-not-in-shapes, .cushion-not-in-shapes, .radiant-not-in-shapes, .oval-not-in-shapes, .marquise-not-in-shapes, .pear-not-in-shapes, .heart-not-in-shapes").click (function () {
		event.preventDefault();
		alert("This shape is not avaliable for this diamond ring");
	 });
    
	// DETAILED VIEW - OPEN POPUP 
	 $("a.view").live("click", function () {
	 	id = $(this).attr("rel");
		// OPEN POPUP
	 	$("#dialog-view").dialog({ width: 820, minHeight: 700, modal: true, draggable: false, resizable: false, dialogClass: 'view-dialog', open: function() { $("#dialog-view").load("/ajax/loose-diamonds-view.php?id=" + id);}} );
		
		// CLOSE POPUP
		$('.ui-widget-overlay').live("click", function() { $("#dialog-view").dialog("close"); $("#dialog-view").html(""); });   
		$('.close-dialog').live("click", function() { $("#dialog-view").dialog("close"); $("#dialog-view").html(""); });   
	 } );
	 
    // DETAILED VIEW - SELECT IMAGE

	 $("a.loose-diamonds-view-thumb").live("click", function () {
	 	rel = $(this).attr("rel");
	 	$(".loose-diamonds-view-image").fadeOut("fast", function() { $(".loose-diamonds-view-image").attr("src", rel).fadeIn(); });
	 } );
	 
	// BUY / ADD DIAMOND BUTTONS
	 $("a.buy, a.add-diamond").live("click", function () {
		if($("a.product-link-buy").hasClass("diamond-required"))
		{	
			$("a.product-link-buy").removeClass("diamond-required");
			$(".product-diamonds-filter").slideUp();
			$(".table-loose-diamonds").hide();
			$(".dataTables_wrapper").hide();
			$(".paging_full_numbers").slideUp();
			$("a.product-link-add-diamond").removeClass("added-diamon-button");			
			$("#product-price-add-diamond").hide();
			$("#product-add-to-cart").slideDown();
			$(".diamon-text").hide();
			$(".added-diamon-text").slideDown();
			query = "?product_id=" + $(".product-id").val();			
			$(".diamond-id").val($(this).attr("rel"));			
			$.get("/ajax/calls-products.php" + query, { action: "update-price", id: $(this).attr("rel"), time: Math.random() }, function(data){ 
				$(".product-price").html(data);
			});			
			$.get("/ajax/calls-products.php" + query, { action: "update-diamond", id: $(this).attr("rel"), time: Math.random() }, function(data){ 
				$(".diamond-detail").html(data);
			});
			
			$(".product-details").slideDown();
		}
		else
			$.get("/ajax/calls-cart.php?id=" + $(this).attr("rel"), { action: "add-item", time: Math.random() }, function(data){ 	document.location = "/cart.html"; });
			$("#dialog-view").dialog("close"); $("#dialog-view").html("");
		});
	// COMPARE BUTTON
	 $("a.compare").live("click", function () {
		$.get("/ajax/loose-diamonds-compare.php?id=" + $(this).attr("rel"), { action: "compare-add-item", time: Math.random() }, function(data){ oTableFavorites.fnDraw(); });
	 } );
	
	// REMOVE COMPARE BUTTON
	 $("a.remove").live("click", function () {
		$.get("/ajax/loose-diamonds-compare.php?id=" + $(this).attr("rel"), { action: "compare-del-item", time: Math.random() }, function(data){ oTableFavorites.fnDraw(); });
	 } );
	 
	// ENQUIRE POPUP (CLOSES DETAILED VIEW)
	  $("a.loose-diamonds-enquire").live("click", function () {
		$("#dialog-view").dialog("close");
		$("#dialog-view").html("");
		
	  	$.get("/ajax/contact.php", { action: "loose-diamond", id: $(this).attr("rel"), time: Math.random() }, function(data){ $("#contact-bg").fadeIn('slow'); $("#contact-box").html(data); $("#contact-box").fadeIn('slow'); });
	 } );
	 
	 // ENQUIRE ABOUT EXPERT SEARCH
	 $("a.contactus").live("click", function () {
	 	
		// OPEN POPUP
		$.get("/ajax/contact.php", { time: Math.random() }, function(data){ $("#contact-bg").fadeIn('slow'); $("#contact-box").html(data); $("#contact-box").fadeIn('slow'); });		
	 } );
	 
}


//////////////////////////////////////////////////////////////////
//																//
// DIAMOND RING FUNCTIONS										//
//																//
//////////////////////////////////////////////////////////////////

function diamondRingsFunctions ()
{
	// FILTERS - SET VARIABLES
    var shape_binary = 100000000000;
	var sort_order = $(".diamond-rings-sorting").val();
	
	// DIAMOND RINGS - CONFIGURE TABLE
    var oTable = $('#table-diamond-rings').dataTable( {
        "aoColumns": [ 
            { "bSortable": false, "sClass": 'center' },
            { "bSortable": false, "sClass": 'center' },
            { "bSortable": false, "sClass": 'center' },
            { "bSortable": false, "sClass": 'center' }
            ],
		"bInfo": false,
        "bFilter": false,
        "bLengthChange": false,
        "bProcessing": true,
        "bServerSide": true,
        "iDisplayLength": 40,
        "sPaginationType": "full_numbers",
        "sAjaxSource": "/ajax/diamond-rings.php",
        "fnServerData": function ( sSource, aoData, fnCallback ) {
            /* Add some extra data to the sender */
            aoData.push(
                        { "name": "shape_binary", "value": shape_binary },
						{ "name": "sort_order", "value": sort_order }
                        );

            $.getJSON( sSource, aoData, function (json) { 
                /* Do whatever additional processing you want on the callback, then tell DataTables */
				fnCallback(json)
            } );
			
        }
    } );
	
	
	//$(".round").click (function () { if ($(this).hasClass("round-active")) { $(this).removeClass("round-active"); shape_binary -= 1; oTable.fnDraw(); } else { $(this).addClass("round-active"); shape_binary += 1; oTable.fnDraw(); } } );
	$(".style-solitare").click (function () { if ($(this).hasClass("style-solitare-active")) { $(this).removeClass("style-solitare-active"); shape_binary -= 1; oTable.fnDraw(); } else { $(this).addClass("style-solitare-active"); shape_binary += 1; oTable.fnDraw(); } } );
	$(".style-band").click (function () { if ($(this).hasClass("style-band-active")) { $(this).removeClass("style-band-active"); shape_binary -= 10; oTable.fnDraw();  } else { $(this).addClass("style-band-active"); shape_binary += 10; oTable.fnDraw();  } } );
	$(".style-multiple").click (function () { if ($(this).hasClass("style-multiple-active")) { $(this).removeClass("style-multiple-active"); shape_binary -= 100; oTable.fnDraw();  } else { $(this).addClass("style-multiple-active"); shape_binary += 100; oTable.fnDraw();  } } );
	$(".style-all").click (function () { if ($(this).hasClass("style-all-active")) { $(this).removeClass("style-all-active"); shape_binary -= 1000; oTable.fnDraw();  } else { $(this).addClass("style-all-active"); shape_binary += 1000; oTable.fnDraw();  } } );
	$(".metal-white").click (function () { if ($(this).hasClass("metal-white-active")) { $(this).removeClass("metal-white-active"); shape_binary -= 10000; oTable.fnDraw();  } else { $(this).addClass("metal-white-active"); shape_binary += 10000; oTable.fnDraw();  } } );
	$(".metal-yellow").click (function () { if ($(this).hasClass("metal-yellow-active")) { $(this).removeClass("metal-yellow-active"); shape_binary -= 100000; oTable.fnDraw();  } else { $(this).addClass("metal-yellow-active"); shape_binary += 100000; oTable.fnDraw();  } } );
	$(".metal-platinum").click (function () { if ($(this).hasClass("metal-platinum-active")) { $(this).removeClass("metal-platinum-active"); shape_binary -= 1000000; oTable.fnDraw();  } else { $(this).addClass("metal-platinum-active"); shape_binary += 1000000; oTable.fnDraw();  } } );
	$(".metal-palladium").click (function () { if ($(this).hasClass("metal-palladium-active")) { $(this).removeClass("metal-palladium-active"); shape_binary -= 10000000; oTable.fnDraw();  } else { $(this).addClass("metal-palladium-active"); shape_binary += 10000000; oTable.fnDraw();  } } );
	$(".shape-princess").click (function () { if ($(this).hasClass("shape-princess-active")) { $(this).removeClass("shape-princess-active"); shape_binary -= 100000000; oTable.fnDraw();  } else { $(this).addClass("shape-princess-active"); shape_binary += 100000000; oTable.fnDraw();  } } );
	$(".shape-round").click (function () { if ($(this).hasClass("shape-round-active")) { $(this).removeClass("shape-round-active"); shape_binary -= 1000000000; oTable.fnDraw();  } else { $(this).addClass("shape-round-active"); shape_binary += 1000000000; oTable.fnDraw();  } } );
	$(".shape-all").click (function () { if ($(this).hasClass("shape-all-active")) { $(this).removeClass("shape-all-active"); shape_binary -= 10000000000; oTable.fnDraw();  } else { $(this).addClass("shape-all-active"); shape_binary += 10000000000; oTable.fnDraw();  } } );
	
	$(".diamond-rings-sorting").change (function (){ sort_order = $(this).val(); oTable.fnDraw(); } );
	
	$(".diamond-rings-showing").change (function (){ 
		var oSettings = oTable.fnSettings();
		oSettings._iDisplayLength = $(this).val();
		oTable.fnDraw();
	} );
	
	diamondRingsTable(shape_binary);
}

function diamondRingsTable(shape_binary_num, sort_order_num)
{
	//$.get("/dev-server/ajax/diamond-rings.php", { shape_binary: shape_binary_num, sort_order: sort_order_num }, function(data){ document.getElementById('sqltesting').innerHTML = data; });
}

//////////////////////////////////////////////////////////////////
//																//
// PRODUCT FUNCTIONS											//
//																//
//////////////////////////////////////////////////////////////////

function productFunctions (imgCount)
{
	// IMAGE CAROUSEL - INITIALIZE
	if (imgCount > 4)
		$(".product-carousel").jCarouselLite({ btnPrev: ".product-thumb-left", btnNext: ".product-thumb-right", visible: 4 });
	
	 // IMAGES - ON CLICK
	 $("a.product-thumb").live("click", function () {
	 	$rel = $(this).attr("rel");
	 	$(".product-image").fadeOut("fast", function() { $(".product-image").attr("src", $rel).fadeIn(); });
	 } );
	 
	// MORE INFO - ON CLICK
	 $("a.product-link-more").live("click", function () {
	 	if ($(".product-description-more").css("display") == "none")
	 		$(".product-description-more").slideDown();
	 	else
			$(".product-description-more").slideUp();
	 } );
	// MORE DETAIL - ON CLICK 
	 $("a.diamond-link-more").live("click", function () {
	 	if ($(".diamond-detail-more").css("display") == "none")
	 		$(".diamond-detail-more").slideDown('slow');
	 	else
			$(".diamond-detail-more").slideUp('slow');
	 } );
	// BUY - ON CLICK
	 $("a.product-link-buy, .product-price-add").live("click", function () {
	 	query = "?id=" + $(this).attr("rel");
				
		$('.product-options').each(function(i){ query = query + "&product_options[]=" + $(this).val(); });
		
		if ($("a.product-link-buy").hasClass("diamond-required"))
		{	
			$(".product-details").slideUp();
			$(".product-diamonds-filter").slideDown();
			$(".table-loose-diamonds").slideDown();
			$(".dataTables_wrapper").slideDown();
			$(".paging_full_numbers").slideDown();
			$(document).ready( looseDiamondFunctions );
		}
		else
		{
			if($(".diamond-id").val()!="")
			{
				query = "?id=" + $(".diamond-id").val();
				$.get("/ajax/calls-cart.php" + query, { action: "add-item", time: Math.random() }, function(data){});
				query = "?id=" + $(this).attr("rel");	
				$('.product-options').each(function(i){ query = query + "&product_options[]=" + $(this).val(); });
			}	
			$.get("/ajax/calls-cart.php" + query, { action: "add-item", time: Math.random() }, function(data){
				document.location = "/cart.html";
			}); 	
		}	
			
	 } );
	 $("a.product-link-add-diamond").live("click", function () {
		
	 	query = "?id=" + $(this).attr("rel");
		$('.product-options').each(function(i){ query = query + "&product_options[]=" + $(this).val(); });
		$(".product-details").slideUp();
		$(".product-diamonds-filter").slideDown();
		$(".table-loose-diamonds").slideDown();
		$(".dataTables_wrapper").slideDown();
		$(".paging_full_numbers").slideDown();
		if($("a.product-link-add-diamond").hasClass("added-diamon-button"))
		{
			$(document).ready( looseDiamondFunctions );			
		}	
		else
		{
			$("a.product-link-buy").addClass("diamond-required");
		}
	
	 } );
	 // OPTIONS - UPDATE PRICE
	 $(".product-options").change( function () {
		query = "?id=" + $(".product-id").val();
		
		$('.product-options').each(function(i){ query = query + "&product_options[]=" + $(this).val(); });

		$.get("/ajax/calls-products.php" + query, { action: "product-price", time: Math.random() }, function(data){ 
			$(".product-price").html(data);
		});
	} );
	
	$(".search-diamond").live("click",function (){ 
            //$(this).animate(function(){ 
        $('html, body').animate({ 
            scrollTop: $(".table-loose-diamonds").offset().top 
        }, 1000); 
            //}); 
     }); 
	// PRODUCT VIDEO - ON CLICK
	 $("a.product-link-video").live("click", function () {
	 	$.get("/ajax/products-video.php?id=" + $(this).attr("rel"), { time: Math.random() }, function(data){ $("#video-bg").fadeIn('slow'); $("#video-box").html(data); $("#video-box").fadeIn('slow'); });
	 } );
	 
	// PRODUCT VIDEO - CLOSE
	$("#video-product-link, #video-bg").live("click", function(){
		$("#video-box").hide();
		$("#video-box").html('');
		$("#video-bg").hide();
	});
}

function php_encode (string)
{
	return escape(string).replace(/\+/g,'%2B').replace(/%20/g, '+').replace(/\*/g, '%2A').replace(/\//g, '%2F').replace(/@/g, '%40');
}



 

