
function initProfile(_minPrice, _maxPrice, _age) {

	var minPrice = _minPrice;
	var maxPrice = _maxPrice;
	var age = _age;
	
	if (maxPrice<=0) {
		maxPrice = 2000;
	}
	$("#man").click(function() {
		if ($('#man').hasClass("genderOn")) {
			$('#man').removeClass("genderOn");	
			$('input[name="gender"]')[0].checked = false;
		} else {
			$('#man').addClass("genderOn");
			$('#woman').removeClass("genderOn");
		}
		$.get("/ajax/profile.html?action=setGender", {gender:"man", date:new Date().getTime()}, function() {updataGuiCommon();});
	});
	$("#woman").click(function() {
		if ($('#woman').hasClass("genderOn")) {
			$('#woman').removeClass("genderOn");
			$('input[name="gender"]')[1].checked = false;
		} else {
			$('#woman').addClass("genderOn");
			$('#man').removeClass("genderOn");
		}
		$.get("/ajax/profile.html?action=setGender", {gender:"woman", date:new Date().getTime()}, function() {updataGuiCommon();});
	});

	
	 $("#ageSlide").slider(
    	{
			stepping: 1,
			min: -1, 
			max: 99,
			slide : function( e, ui) {
				var age = ui.value;
				if (age <0) {
					age = "Ange &aring;lder";
					document.getElementById('manLabel').innerHTML = " Man";
					document.getElementById('womanLabel').innerHTML = " Kvinna";
				} else {
					if (age > 24 || age<0) {
						document.getElementById('manLabel').innerHTML = " Man";
						document.getElementById('womanLabel').innerHTML = " Kvinna";
					} else {
						document.getElementById('manLabel').innerHTML = " Kille";
						document.getElementById('womanLabel').innerHTML = " Tjej";
					}
					age = age + " &aring;r";
				}
				document.getElementById('ageSpan').innerHTML = age;
			},
			change : function( e, ui) {
				$.get("/ajax/profile.html?action=setAge", {age:ui.value, date:new Date().getTime()}, function() {updataGuiCommon();});
			},			
			handles: [
				{start: age, min: -1, max: 100}
			]
	    }
    );
	
    $("#priceSlide").slider(
    	{
			stepping: 100,
			min: 0, 
			max: 2000,
			slide : function( e, ui) {
				var minValue = $('#priceSlide').slider('value', 0); 
				var maxValue = $('#priceSlide').slider('value', 1);
				var text = minValue + "-" + maxValue;
				if (maxValue == 2000) {
					maxValue = "";
				}
				document.getElementById('priceSpan').innerHTML = minValue + " - " + maxValue;
			},
			change : function( e, ui) {
				var minValue = $('#priceSlide').slider('value', 0); 
				var maxValue = $('#priceSlide').slider('value', 1);
				$("#priceSpan").load("/ajax/profile.html?action=setPrice", {minPrice:minValue, maxPrice:maxValue, date:new Date().getTime()}, function() {updataGuiCommon();});
			},
			range: true,			
			handles: [
				{start: minPrice, min: 0, max: 2000},
				{start: maxPrice, min: 0, max: 2000}
			]
	    }
    );
}

function updataGuiCommon() {

	if(typeof updateGui == 'function') { 
		updateGui();	
	} 
}

function loadVideo(id, url) { 			
	$("#videoWrapper").show();
	$.get(url + "?action=showVideo",{ videoId: id }, function(data){
			$("#videoPlayerDiv").html(data);
	});
}

function closeVideo() { 			
	$("#videoPlayerDiv").html("");			
	$("#videoWrapper").hide(); 
}

function addFavorite(id, pageName) {	
	$("#favoritesDiv").load("/ajax/profile.html?action=addFavorite", {productId:id, date:new Date().getTime()});
	$("#favoriteLinkImageHolder").html("");
	$("#favoriteLinkTextHolder").html("<small>Favorit tillagd i kolumnen till v&auml;nster</small>");
	pageTracker._trackEvent('Favorites', 'Add favorite', id + " - " + pageName);	
}

function trackFacebook(productName) {
	pageTracker._trackEvent('Facebook', 'Share', productName);
}

function clickOut(company, price, productId, name, category, visitorId, linkObj) {	
	
	var orderId = visitorId + "_" + Math.floor(Math.random()*1000);	
	// alert("clickOut\norderId=" + orderId + "\nCompany=" + company + "\nPrice=" + price + "\nProductID=" + productId + "\nName=" + name + "\nCategory=" + category + "\nVisitorId=" + visitorId);
  	pageTracker._addTrans(orderId, company, price, "", "", "", "", "");
	pageTracker._addItem(orderId, productId, name, category, price, "1");
	pageTracker._trackTrans();
	
	if (linkObj) {
		if (linkObj.href) {
			var url = linkObj.href;
			url = url.substring(url.indexOf("/transition"))
			pageTracker._trackPageview(url);
		}
	}
	
	return true;
}
