jQuery(document).ready(function() {
	// When the add button is clicked:
	jQuery('.addshortlist').click(function() {
		var currentId = jQuery(this).attr('id');
		var getRw = jQuery.cookie('rw_shortlistc');
		
		if(getRw == null){
			jQuery.cookie('rw_shortlistc','xxx', { expires: 7, path:"/"});
			getRw = jQuery.cookie('rw_shortlistc');
			
		} 
		var getClass = jQuery(this).attr('class');
		
		if (getClass == 'deleteshortlist') {
			//delete
			
			jQuery("#"+ currentId).attr('src', '/wp-content/plugins/rwProperty/images/star-clear.gif');
			jQuery("#"+ currentId).attr('title', 'Click star to add to Favourites');
			jQuery("#"+ currentId).attr('alt', 'Click star to add to Favourites');	
			jQuery("#"+ currentId).attr('class', 'addshortlist'); 			
			//jQuery("#"+ currentId + "outer").css("display","none");
			if(!window.location.search.substring(1)){
				jQuery("#"+ 'p'+currentId.substring(1)).css("display","none");
			}
			jQuery("#"+ 'fl'+currentId.substring(1)).css("display","none");
			
						
			var arrGetIds = getRw.split( "-" );
			var indexRw = jQuery.inArray(currentId,arrGetIds)
			var new_rw = "";
			for (var i = 0; i < arrGetIds.length; i++) {
				if(i != indexRw){
					if(new_rw.length == 0) {
						new_rw = arrGetIds[i];
					} else {
						new_rw = new_rw + '-' + arrGetIds[i];
					} 
				}
			}
			
			jQuery.cookie('rw_shortlistc', new_rw, { expires: 7, path:'/'});
					
			
		} else {
			
			jQuery("#"+ currentId).attr('src', '/wp-content/plugins/rwProperty/images/star-yellow.gif'); 
			jQuery("#"+ currentId).attr('title', 'Click star to remove from Favourites');
			jQuery("#"+ currentId).attr('alt', 'Click star to remove from Favourites');	
			jQuery("#"+ currentId).attr('class', 'deleteshortlist');
			
			
				var arrGetIds = getRw.split( "-" );
				
				if(jQuery.inArray(currentId,arrGetIds) < 0) {
					var new_rw = getRw + '-' + currentId;
					jQuery.cookie('rw_shortlistc', new_rw, { expires: 7, path:'/'});
					
				}
			
		}
		
	});
		
	var getRw = jQuery.cookie('rw_shortlistc');
		if(getRw == null){
			jQuery.cookie('rw_shortlistc','xxx', { expires: 7, path:'/'});
			getRw = jQuery.cookie('rw_shortlistc');
		}
	var arrGetIds = getRw.split( "-" );
	
	jQuery('.addshortlist').each(function() {
		thisID = jQuery(this).attr('id');
		if(jQuery.inArray(thisID,arrGetIds) >= 0) {
			jQuery("#"+ thisID).attr('class', 'deleteshortlist'); 
			jQuery("#"+ thisID).attr('src', '/wp-content/plugins/rwProperty/images/star-yellow.gif');
			jQuery("#"+ thisID).attr('title', 'Click star to remove from Favourites');
			jQuery("#"+ thisID).attr('alt', 'Click star to remove from Favourites');	
		} else {
			jQuery("#"+ thisID).attr('title', 'Click star to add to Favourites');
			jQuery("#"+ thisID).attr('alt', 'Click star to add to Favourites');
		
		}
	});

});




