jQuery.unparam = function (value) {
    var
    // Object that holds names => values.
    params = {},
    // Get query string pieces (separated by &)
    pieces = value.split('&'),
    // Temporary variables used in loop.
    pair, i, l;

    // Loop through query string pieces and assign params.
    for (i = 0, l = pieces.length; i < l; i++) {
        pair = pieces[i].split('=', 2);
        // Repeated parameters with the same name are overwritten. Parameters
        // with no value get set to boolean true.
        params[decodeURIComponent(pair[0])] = (pair.length == 2 ?
            decodeURIComponent(pair[1].replace(/\+/g, ' ')) : true);
    }

    return params;
};






////////////////////// 

var cookieList = function(cookieName) {
	
	var cookie = $.cookie(cookieName);
	var items = cookie ? cookie.split(/,/) : new Array();

	return {
	    "add": function(val) {
	    	a = decodeURIComponent($.param(val));
			items[items.length]= a;
			items.reverse(); 
			items = jQuery.unique(items);
			if(items.length > 5){
				items = items.slice(1,6);
			}	        
			$.cookie(cookieName, items,{ expires: 7, path: '/'});
	    },
	    "clear": function() {
	        $.cookie(cookieName, null,{ expires: 7, path: '/'});
	    },
	    "items": function() {
	    	a = new Array();
			for (var i = 0, j = items.length; i < j; i++) {
				a.push($.unparam(items[i]));
			}
	        return a;
	    }
	  }
}

function setoffreconsultee(ref,infobien){

	var list = new cookieList("offreconsultee");
	list.add(infobien);
	
}

function getoffreconsultee(label){

	var list = new cookieList("offreconsultee");
	var a = list.items();
	var divDatas = "";

	if(a.length > 0)
		{
		for (var i = 0, j = a.length; i < j; i++) 
			divDatas += "<div class='biensvisites'><a href='"+a[i]["url"]+"'><img src='"+a[i]["photo"]+"' alt='' width='159' height='106' /></a><div class='visitestitres'><div class='transpLegend'>&nbsp;</div><p class='legend'>"+a[i]["ville"]+" "+a[i]["prix"]+"</p></div><a class='plus' href='"+a[i]["url"]+"'>"+a[i]["label"]+"</a></div>";
		
		$("#consultes").show();
		var ancienHtmlContenu = $("#consultes").html();
		$("#consultes").html(ancienHtmlContenu+divDatas);
		}
	
}

function sauvegardeTwimit(){
	z = document.createElement('script');
	z.src='/apps/add';
	document.body.appendChild(z);
}


$(document).ready(function(){

	$(".legendnew").diaporama({
		animationSpeed: "slow",
		delay:4
	});

});

