/**
主体的javascript代码
*/
function vote_load(index){
	if(!$("#voteFeedback"+index).hasClass("vote_loading")){$("#voteFeedback"+index).empty().addClass("vote_loading")};
}
function vote_loaded(index){
	if($("#voteFeedback"+index).hasClass("vote_loading")){$("#voteFeedback"+index).removeClass("vote_loading")};
}
function oneClickVote(rv_author_id,vote_val,vote_ip,pID,rvID,index,iniframe,action){
	//rv:means review; vote_val:click yes,the value equal 1,click no, value equal 0; pID:means products_id;index: use to make difference from  one and another review; iniframe:whether the colorbox is in an iframe; action:two choise: "review_vote" and "comments_voting"
	$.post($("#vote_processor").val(),{
		rv_author_id:rv_author_id,
		reviews_id:rvID,
		voting_value:vote_val,
		voter_ip:vote_ip,
		products_id:pID,
		action:action
	},function(xhtml){
		if($("#voteFeedback"+index).hasClass("vote_loading")){$("#voteFeedback"+index).removeClass("vote_loading")};
		if(iniframe==1){
			self.parent.$("#voteFeedback"+index).empty().append(xhtml);
		}else{
			$("#voteFeedback"+index).empty().append(xhtml);
		}
	});
}
function btnAddCart(index){
	var how_many = $("#p_list_add_"+ index + ",#cart_quantity").val();
	$("#p_list_add_"+ index + ",#cart_quantity").val(parseInt(how_many)+1);
	$("#p_list_reduce_"+ index).css("display","inline-block");
	return false;
}
function btnReduceCart(index){
	var how_many = $("#p_list_add_"+index + ",#cart_quantity").val();
	if(parseInt(how_many)>1){
		$("#p_list_add_"+index + ",#cart_quantity").val(parseInt(how_many)-1);
	}
	var how_many = $("#p_list_add_"+index + ",#cart_quantity").val();
	if(parseInt(how_many)<=1){
		$("#p_list_reduce_"+ index).hide();
	}
	return false;
}
function add_this_product(index){
	
	//$("#p_list_add_cart_"+ index).action="http://192.168.0.85/tinydeal/index.php?main_page=products_all";
	$("#p_list_add_cart_"+ index).submit();
	return false;
}
//jquery scrollTo function:
;(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);
//EOF jquery scrollTo function


//获取URL的参数函数

function request(paras){ 
	var url = location.href;  
	var paraString = url.substring(url.indexOf("?")+1,url.length).split("&");  
	var paraObj = {}  
	for (i=0; j=paraString[i]; i++){
		paraObj[j.substring(0,j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=")+1,j.length);  
	}  
	var returnValue = paraObj[paras.toLowerCase()];  
	if(typeof(returnValue)=="undefined"){  
		return "";  
	}else{  
		return returnValue;  
	}  
} 

function gotothere(id) {
    var elem = $('#'+id);
    if (elem.length == 0) {
        document.location.href = $("#browsing").val()+'#'+id;
        return false;
    }
    else {
        scrollToID(id);
    }
if (document.location.href.indexOf('#'+id) > -1) {
    window.setTimeout(function(){scrollToID(id)}, 1000);
}

};
function scrollToID(id) {
jQuery.scrollTo('#'+id, { duration: 1500 });
}
function popupwin(url,name,width,height,options){if($.browser.msie){var win=window.showModelessDialog(url,window,"status:false;dialogWidth:"+(width)+"px;dialogHeight:"+(height+30)+"px;edge:Raised; help: 0; resizable: 0; status: 0;scroll:0;");}
else{xposition=0;yposition=0;if((parseInt(navigator.appVersion)>=4)){xposition=(screen.width-width)/2;yposition=(screen.height-height)/2;}
theproperty="width="+width+","+"height="+height+","+"screenx="+xposition+","+"screeny="+yposition+","+"left="+xposition+","+"top="+yposition+","+options;
var win=window.open(url,name,theproperty);win.focus();}
return false;}

function killerrors() { 
	return true; 
} 
//window.onerror = killerrors;


function addLoadListener(fn)
{
	if (typeof window.addEventListener != 'undefined')
	{
	    window.addEventListener('load', fn, false);
	}
	else if (typeof document.addEventListener != 'undefined')
	{
	    document.addEventListener('load', fn, false);
	}
	else if (typeof window.attachEvent != 'undefined')
	{
		window.attachEvent('onload', fn);
	}
	else
	{
		var oldfn = window.onload;
		if (typeof window.onload != 'function')
		{
		    window.onload = fn;
		}
		else
		{
		    window.onload = function()
		    {
		        oldfn();
		        fn();
		    };
		}
	}
}
//使javascript也能使用trim这些函数
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

//Marquee
(function($){
 var methods = {
 marquee: function marquee(user_settings) {
 var self = $(this);
 var sch = self.attr('scrollHeight');
 self.append(self.html());
 var settings = {
 timeout: null,
 events: {
 play: function(evt) {
 var self = $(this);
 var sct = self.scrollTop();
 if(sct>=sch)self.scrollTop(sct=sct-sch);
 self.animate({scrollTop:sct+settings.step-sct%settings.step},2000,function(){
 if(settings.timeout) clearTimeout(settings.timeout);
 settings.timeout = setTimeout(function(){self.marqueePlay()},settings.time);
  });
  },
 stop: function(evt) {
 var self = $(this);
 clearTimeout(settings.timeout);self.stop();
  }
  }
  };
  if(self.data("marquee.settings")) {
  settings = self.data("marquee.settings");
  }
  settings = $.extend(user_settings, settings);
 for(var event in settings.events) {
  var evt = "marquee." + event;
   self.unbind(evt);
   self.bind(evt, settings.events[event]);
   }
   self.data("marquee.settings", settings);
   self.marqueePlay();
   return self;
   },
   marqueePlay: function() {
   $(this).trigger("marquee.play");
   },
    marqueeStop: function() {
    $(this).trigger("marquee.stop");
    }
    };
    $.each(methods, function(i) {
    $.fn[i] = this;
    });
})(jQuery); 