 	
(function($){
	$.fn.simpleCarousel = function(options) {
		var d = {'btnLeft' : 'move-left', 'btnRight' : 'move-right', 'nbViewItems' : 1, 'nbScrollItems' : 1, 'imgWidth' : 160, 'speed' : 1.5E3};
		var p = $.extend(d, options), action = false, start;
		$('.' + p.btnLeft).click(function(){
			if (action === false) {
				start = parseInt(ul.css('left'), 10);
				if (start >= 0) {
					ul.css('left','0px');
				} else {
					action = true;
					ul.animate({'left': ((start + s > 0) ? 0 : start + s) + 'px'}, p.speed, 'swing', function(){action = false;});
				}
			}
		});
		
		$('.' + p.btnRight).click(function(){
			if (action === false) {
				start = parseInt(ul.css('left'), 10);
				if (start <= -w) {
					ul.css('left', -w + 'px');
				} else {
					action = true;
					ul.animate({'left': ((start - s <= -w) ? -w : start - s) + 'px'}, p.speed, 'swing', function(){action = false;});
				}
			}
		});
		$(this).find('img').each(function(){
			$(this).css({'width':p.imgWidth + 'px', 'margin':'0 auto', 'padding':'1px'}).parent().append('<em>' + $(this).attr('title') + '</em>');
			$(this).attr('title','');
		});
		var li = $(this).find('li');
		li.css({'float':'left', 'margin':'0', 'padding':'1px', 'overflow':'hidden'});
		var liW = li.width() + 2;
		var ul = $(this).find('ul').css({'position':'relative', 'left':'0px', 'margin':'0', 'padding':'0', 'overflow':'hidden', 'list-style':'none'}).width(li.length * liW);
		var w  = (li.length - p.nbViewItems) * liW;
		var s  = p.nbScrollItems * liW;
		$(this).css({'position':'relative', 'margin':'0', 'overflow':'hidden', 'width': (p.nbViewItems * liW) + 'px'});
	};
})(jQuery);



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,5);
			
		}
	    
		$.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;
	    }
	  }
}

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;
};

function setoffreconsultee(ref,infobien){

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

function getoffreconsultee(id){

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

	for (var i = 0, j = a.length; i < j; i++) {
		list.push({'url':a[i]["url"],'photo':a[i]["photo"],'ville':a[i]["ville"],'prix':a[i]["prix"]});
	}

	var markup = "<li><a class='txt_jaune_bold float_left' href='${url}'><img src='${photo}' width='90' height='60' alt='' /></a><a class='float_right' href='${url}' title='${ville} ${prix}' >${ville}<br/>${prix} €</a>";
	$.template( "movieTemplate", markup );
	$.tmpl( "movieTemplate", list).appendTo( "#consultes" );

}


