$(document).ready(function(){
	$('.product-images').click(function() {
		$(this).showPopup();
		return false;
	});
        
	    $(".hndl_show_login").click(function(){
		$("#block-customerinfo").toggle();
		$("#block-auth").toggle();
		return false;
	    });
	    $("#hndl-show-billing-address").click(function(){
		$("#block-billing-address").toggle();
		//return false;
	    });
	    $("#hndl-show-loginpass-fields").click(function(){
		$("#block-loginpass-fields").toggle();
		//return false;
	    });
	    $(".country_box").change(function(){
			$("#block-customerinfo").attr("action","update_form");
			$("#block-customerinfo").submit();
		return false;
	    });
	    
	    $(".autofill").focus(function(){
			_this = $(this);
			
			if(_this.attr("value"))return false;
			
			var obj = $("#"+$(_this).attr("rel")).attr("value");
			//alert(obj);
			if(!obj)return false;
			
			_this.attr("value",obj);

		return false;
	    });
            

            
});

 $.fn.showPopup = function(_href){
    var $link = $(this).attr("href");
     //detect whether popup is visible or not
     $("body").prepend("<div id='opaco' style=' background-color:#000000; cursor:pointer; display:none; left:0; position:absolute; top:0; opacity:.7; filter: alpha ( opacity = 70); width:100%; z-index:1000;'></div>");
	$('#opaco').height($(document).height()).fadeIn(500).click(function(){hidePopup();});
    $(this).preload({onComplete:function(){
            $("body").prepend("<div id='image' style='display:none; position:relative; height:600px; left:50%; top:50%; position:fixed; z-index:1001;'><img src="+$link+"  /></div>");
            var marginLeft =  -  $('#image').width()/2 + 'px';
            var marginTop =  -  $('#image').height()/2 + 'px';
            $('#image').animate({marginLeft: marginLeft, marginTop: marginTop}, 500);
            $('#image').fadeIn(400).click(function(){hidePopup();});
        }});

};

function hidePopup(){
	$('#image').fadeOut(300, function(){$('#image').remove();});
	$('#opaco').fadeOut(500, function(){$('#opaco').remove();});
};



function open_window(link, w, h) {

	var win = "width=" + w + ",height=" + h
			+ ",menubar=no,location=no,resizable=yes,scrollbars=yes";
	var newWin = window.open(link, 'newWin', win);
	if (newWin) {
		newWin.focus();
	}
	return newWin;
}