/* alert("JS loaded"); */

$(document).ready(function() {
	
	//-- open new address div
	$("#openlink").click(function(event) {
		event.preventDefault();
		$("#c-newaddress").slideToggle("slow", callback);
	});
	
	$("#canceladdress").click(function(event) {
		event.preventDefault();
		$("#c-newaddress").slideUp("slow", callback);
	});
	
	/*function callback() {
		$('.vscroll-pane').jScrollPane();
	}*/
	
	//-- show fullsize image
	$("#showfullsize").click(function () {
		$("#fullsizeimg").attr("src", $(this).attr("href"));
		//$("#fullsizeimg").attr("height", 750);
		$("#detailimg").css({ display : "block"});
		//$('.dscroll-pane').jScrollPane();
		return false;
	});
	//-- hide fullsize image
	$("#close").click(function () {
		$("#detailimg").css({ display : "none"});
		return false;
	});
	
	//-- switch thumb images
	$("a.productthumblink").click(function () {
	
		//-- set topmargin for the ra_ image
		var dim = $(this).prev().find("img").attr("class").split(" ");
		var margin = dim[1];
		//alert(margin);
		$("img.productmainimg").attr("style", "margin-top:"+margin+"px;");
		 
		//-- make ra_ image path
		var img = $(this).attr("href");
		var string = img.split("tmb");
		var url = string[0] + 'ra' + string[1];
		
		$("img.productmainimg").attr("src", url);
		$("#showfullsize").attr("href", $(this).attr("id"));
		
		//-- set height of fullsize image for scrolling
		var dim = $(this).attr("class").split(" ");
		var height = dim[1];
		$("#fullsizeimg").attr("height", height);
		
		return false;
	});
	
	/* login block fns */
	
	
	//-- show login screen
	$(".loginlink").click(function () {
		$("#login").css({ display : "block"});
		return false;
	});
	
	//-- show login screen
	$(".requirelogin").click(function () {
		$("#login").css({ display : "block"});
		$("#loginaction").val("gotoOrderConfirmation");
		return false;
	});
	
	
	//-- hide login screen
	$("#logincancel").click(function () {
		$("#loginemail").val("email");
		$("#loginpw").val("password");
		$("#login").css({ display : "none"});
		return false;
	});
	
	//-- clear input fields on focus
	$("#login input[type=text]").focus(function () {
         $(this).val('');
    });
    
    
    //-- get size select for colour
    $("select.colour").change(function () {
    	$colour = $(this).val();
    	$id = $(this).attr("id").split('-');
    	$id = $id[1];
        
        $.get("http://rashop.site/login/components/public/main.php", { action : "getColourSizes", colour: $colour, id: $id},
			function(data){
				$("#size").replaceWith(data);
		});
        //alert($id);
    });
    
    
   //-- set order
    $("#setorder").click(function () {
    	
		var insurance = $("#insurance").attr("checked");
		//alert(insurance);
		
		$.get("http://shop.ra13.be/login/components/public/main.php", { action : "setOrder", insurance: insurance},
			function(data){
				$("#paypalform").submit();
		});
		
		//return false;
	});
	
	//-- submenu navigation
	$('.designers').hover(function() {
		$('#remote .subnav').show();
	}, function() {
		$('#remote .subnav').hide();
	});
    
});