/*jredirect*/
jQuery.extend({
  jredirect: function(options) {
    var defaults = {
      uri: location.href.split('&amp;').join('&').split('#')[0],
      method: 'get',
      data: {},
			target:'_self'
    }  
    var options =  $.extend(defaults, options);
    $('#jredirect').remove();
    var html='';
    for (i in options.data) html+='<input type="hidden" id="'+i+'" name="'+i+'" value="'+options.data[i]+'" />';
    $('body').append('<form id="jredirect" method="'+options.method+'" target="'+options.target+'" action="'+options.uri+'">'+html+'</form>');
    $('#jredirect').submit(); 
  }
});  

/*jeval*/
jQuery.extend({
  jeval: function(o) {
    if (typeof(o)=='object') {
      return o;
    } else {
      try {
        return eval('('+o+')');
      } catch(e) {
        return {};
      }  
    }
  }
});  

function number_format( number, decimals, dec_point, thousands_sep ) {
	var n = number, c = isNaN(decimals = Math.abs(decimals)) ? 2 : decimals;
	var d = dec_point == undefined ? "," : dec_point;
	var t = thousands_sep == undefined ? "." : thousands_sep, s = n < 0 ? "-" : "";
	var i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
	return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
}
	
Object.size = function(obj) {
    var size = 0, key;
    for (key in obj) {
        if (obj.hasOwnProperty(key)) size++;
    }
    return size;
};

this.imagePreview = function(elem){	
	
	xOffset = 10;
	yOffset = 30;
		
	$(elem).hover(function(e){
		this.t = this.title;
		this.title = '';	
		var c = (this.t != '') ? '<br/>' + this.t : '';
		$('body').append('<p id="preview"><img src="'+ this.src.split('s_logo_').join('') +'" alt="Image preview" />'+ c +'</p>');								 
		$('#preview')
			.css('top',(e.pageY - xOffset) + 'px')
			.css('left',(e.pageX + yOffset) + 'px')
			.fadeIn('fast');						
  },
	function(){
		this.title = this.t;	
		$('#preview').remove();
  });
	
	$(elem).mousemove(function(e){
		$('#preview')
			.css('top',(e.pageY - xOffset) + 'px')
			.css('left',(e.pageX + yOffset) + 'px');
	});
	
};

$(document).ready(function(){
	imagePreview('.product_image');
});
