var launchbox = (function(){
	var thisHash = window.location.hash;
  
	$(document).ready(function() {
		if(window.location.hash) {
			$(thisHash).fancybox({
				type		: "ajax",
			  	maxWidth	: 700,
			  	minHeight	: 400,
			  	maxHeight	: 600,
			  	fitToView	: false,
			  	width		: '70%',
			  	height		: '70%',
			  	autoSize	: true,
			  	closeClick	: false,
			  	openEffect	: 'none',
			  	closeEffect	: 'none',
			  	helpers: {
					overlay : {
						closeClick : false,
						css        : {
							'background' : 'rgba(87,120,165,0.55)'
						}
				  	}
			  	}
			}).trigger('click');
		}
		$(".softDown").fancybox({
			type		: "ajax",
			maxWidth	: 700,
			minHeight	: 400,
			maxHeight	: 600,
			fitToView	: false,
			width		: '70%',
			height		: '70%',
			autoSize	: true,
			closeClick	: false,
			openEffect	: 'none',
			closeEffect	: 'none',
			helpers: {
			  	overlay : {
					  closeClick : false,
					  css        : {
						  'background' : 'rgba(87,120,165,0.55)'
					}
				}
			}
		});
	});
});

$(document).ready(function() {
	$('.fancybox').fancybox({
		openEffect : 'fade',
		openSpeed  : 150,
		closeEffect : 'fade',
		closeSpeed  : 150,
		aspectRatio : true,
		scrolling   : 'no',
		helpers: {
			title : {
				type : 'inside'
			},
			overlay : {
				css : {
	   'background' : 'rgba(87,120,165,0.55)'
				}
			}
		}
	});
	$(".softDown").fancybox({
			type		: "ajax",
			maxWidth	: 700,
			minHeight	: 400,
			maxHeight	: 600,
			fitToView	: false,
			width		: '70%',
			height		: '70%',
			autoSize	: true,
			closeClick	: false,
			openEffect	: 'none',
			closeEffect	: 'none',
			helpers: {
			  	overlay : {
					  closeClick : false,
					  css        : {
						  'background' : 'rgba(87,120,165,0.55)'
					}
				}
			}
		});
});



$.getJSON('/json/ipgeo', (function(data) {
	console.log(data);
	var ipcode = data.ipgeocode;
	console.log('The ipcode is '+ipcode);

	if (ipcode == 'GB'){	//UK Pound
		$(".donate").html("&pound;1");
	}
	else if (ipcode == 'US'){	//US Dollar
		$(".donate").html("US&dollar;1.65");
	}
	else if (ipcode == 'AD' || ipcode == 'AT' || ipcode == 'BE' || ipcode == 'CY' || ipcode == 'EE' || ipcode == 'FI' || ipcode == 'FR' || ipcode == 'DE' || ipcode == 'GR' || ipcode == 'IE' || ipcode == 'IT' || ipcode == 'XK' || ipcode == 'LV' || ipcode == 'LU' || ipcode == 'MT' || ipcode == 'MC' || ipcode == 'ME' || ipcode == 'NL' || ipcode == 'PT' || ipcode == 'SM' || ipcode == 'SK' || ipcode == 'SI' || ipcode == 'ES' || ipcode == 'VA'){$(".donate").html("&euro;1.21");}
	else {	//USDollar - catch all
		$(".donate").html("US&dollar;1.65");
	}

}));

// validate signup form on keyup and submit
var validator = $("#feedback").validate({
	rules: {
		full_name: "required",
		email: {
			required: true,
			email: true
		},
		recommendation: "required"
	},
	// the errorPlacement has to take the table layout into account
	errorPlacement: function(error, element) {
		if (element.is(":radio"))
			error.insertAfter($("#recco"));
		else
			error.appendTo(element.next());
	},
	messages: {
		full_name: "Enter your full name (firstname &amp; lastname)",
		lastname: "Enter your lastname",
		email: {
			required: "You haven't provided a valid Email address. An email address helps when we want to ask more details about your suggestion or already have a work around to do what you want.  Don't worry, we hate spam as much as you do.",
			minlength: "Please enter a valid email address"
		},
		recommendation: "Please select a number on the scale",
	},

	// set this class to error-labels to indicate valid fields
	success: function(label) {
		// set &nbsp; as text for IE
		label.html("&nbsp;").addClass("checked");
	},
	highlight: function(element, errorClass) {
		$(element).parent().next().find("." + errorClass).removeClass("checked");
	}
});

$(document).ready(function() {
  	$('#feedback').submit(function(e) {
    	$.cookie('feedform', 'yes', { path: '/', expires: 999999 });
  	});
});

//launchbox();

$( "#describe" ).change(function() {
	$( ".desdiv" ).addClass("hide");
	$( "#describe option:selected" ).each(function() {
		str = $( this ).val();
		divshow = "div#"+str
	});
	$( divshow ).removeClass("hide");
	console.log("str variable is "+str);
});


$(document).ready(function () {

	$(window).scroll(function(){
		if ($(this).scrollTop() > 100) {$('.scrollup').fadeIn();} else {$('.scrollup').fadeOut();}
	});

	$('.scrollup').click(function(){
		$("html, body").animate({ scrollTop: 0 }, 600);
		return false;
	});

	$("a.zoom").append("<span></span>");

	$(".topTab li.tab, .softPane, .topTab li.tab a").removeClass('active');
	$(".tpn, .softPaneMain").removeClass('active').css('display:none');
	
	$.urlParam = function (name) {
        var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
        if (results == null) {
            return null;
        } else {
            return results[1] || 0;
        }
    }

    var param = $.urlParam('soft');
    var butId = "href='#" + param + "'";
    $(".softTab>li>a["+butId+"]").trigger("click");
    
    document.getElementById("feedback").setAttribute("action", "https://feedback.picotech.com/api/website");

});
