if(typeof jq=="undefined"){try{var jq=$.noConflict();}catch(e){alert(e);}}jq(document).ready(function(){if(jq("#searchform").length==0)return;fnInitSearchAutoComplete('query');});function fnInitSearchAutoComplete(_searchId){fnInitAutoComplete("/Redirect/rpc/all-terms-rpc.php",_searchId,function(_item){if(jq("#search-button").length!=0){jq("#search-button").val("Searching...");jq("#search-button").addClass("bold");}location.href='/search/?s='+encodeURIComponent(_item);});};function fnInitAutoComplete(urlOrData,_searchId,func,_options){_cacheLength=1;_matchSubset=false;if((typeof urlOrData)!='string'){_cacheLength=10;_matchSubset=true;}if(_options==null){_options={};}_options.width=parseInt(_options.width,10)||300;_options.max=_options.max||10;_options.width=_options.width||300;_options.delay=_options.delay||100;_options.cacheLength=_options.cacheLength||_cacheLength;_options.matchSubset=_options.matchSubset||_matchSubset;_options.scroll=_options.scroll||false;_options.selectFirst=_options.selectFirst||false;_options.highlightedInInput=_options.highlightedInInput||true;jq("input#"+_searchId).autocomplete(urlOrData,_options).result(function(event,_item){func(_item);});jq("input#"+_searchId).keyup(function(e){if(e.keyCode==13){func(jq('input#'+_searchId).val());}});};jq.preloadImages=function(){for(var i=0;i<arguments.length;i++){jq("<img>").attr("src",arguments[i]);}};jq.preloadImages("/images/controls-new/blue-processing.gif","/images/controls/slider/tooltipsmall-tail.gif","/images/tooltip-tail.gif","/images/tooltip-tail-right.gif","/images/tooltip-close.gif");jq(document).ready(function(){if(jq("#main-tooltip").css("display")=="block"){fnAdjustMainTooltip();jq(window).resize(fnAdjustMainTooltip);}if(browser.isIE6x){window.setTimeout(function(){fnFixFooter();},30);jq(document).click(fnFixFooter);}if(0!=jq('#homecontent').length){jq('.contents .tabs a').click(function(){jq('.contents .tabs li').removeClass('selected');jq('.contents-panels .panel').hide();jq('.contents-panels .panel-'+jq(this).attr('data-tab')).show();jq(this).parent().addClass('selected');jq(this).blur();return false;});jq('[data-tab=popcat]').trigger('click');}});function fnFixFooter(){jq("#footer").css({bottom:1});jq("#footer").css({bottom:0});};function fnNumberFormat(number){number=number.toString();while(/(-?[0-9]+)([0-9]{3})/.test(number)){number=number.replace(/(-?[0-9]+)([0-9]{3})/,"$1,$2");}return number;};function fnBookmarkPage(url,title){if(window.sidebar){window.sidebar.addPanel(title,url,"");}else if(document.all){window.external.AddFavorite(url,title);}};function fnGetAbsolutePosition(elRef){var res=new Object();res.left=0;res.top=0;if(elRef!==null){res.left=elRef.offsetLeft;res.top=elRef.offsetTop;var offsetParent=elRef.offsetParent;var parentNode=elRef.parentNode;while(offsetParent!==null){res.left+=offsetParent.offsetLeft;res.top+=offsetParent.offsetTop;if(offsetParent!=document.body&&offsetParent!=document.documentElement){res.left-=offsetParent.scrollLeft;res.top-=offsetParent.scrollTop;}if(navigator.userAgent.match(/gecko/i)){while(offsetParent!=parentNode&&parentNode!==null){res.left-=parentNode.scrollLeft;res.top-=parentNode.scrollTop;parentNode=parentNode.parentNode;}}parentNode=offsetParent.parentNode;offsetParent=offsetParent.offsetParent;}}return res;};var gTooltipTimeout=0;function fnShowTooltip(aRef,contentId,lockMark){clearTimeout(gTooltipTimeout);if(aRef.id!=""||typeof contentId!="undefined"){var tcontent=document.getElementById("tooltip-content");tcontent.className="";var content="<div id=\"tooltip-tail\"></div>";content+="<a href=\"javascript:void(0);\" onclick=\"fnCloseTooltip();\" id=\"tooltip-close\"></a>";content+=document.getElementById(contentId).innerHTML;tcontent.innerHTML=content;var position=fnGetAbsolutePosition(aRef);position.left+=(jq(aRef).width()/2)+parseInt(jq("#tooltip-tail").css("width"));position.top+=jq(aRef).height()/2;fnCloseTooltip();jq("#tooltip").css({left:position.left,top:position.top}).show();if(lockMark!=undefined){aRef.src="/images/overlay-qmark-over.gif";}if(position.left+jq("#tooltip").width()>jq(window).width()){var aPos=fnGetAbsolutePosition(aRef);jq("#tooltip-content").addClass("right");jq("#tooltip").css({left:aPos.left-jq("#tooltip").width()});}jq(aRef).add("#tooltip").unbind("mouseover").unbind("mouseout").mouseout(function(){gTooltipTimeout=setTimeout(fnCloseTooltip,2000);}).mouseover(function(){clearTimeout(gTooltipTimeout);});}};function fnCloseTooltip(){var tooltips=["tooltip","tooltipsmall"];for(var i=0;i<tooltips.length;i++){var tooltip=document.getElementById(tooltips[i]);if(tooltip!=null){tooltip.style.display="none";}}jq(".qmark").attr("src","/images/overlay-qmark.gif");};function fnAdjustMainTooltip(){var mt=document.getElementById("main-tooltip");var mf=document.getElementById("main-tooltip-faux");if(mt==null){return;}var ww=jq(window).width();var wd=(ww-1004)/2;mt.style.left=(ww>1004?177+wd:177)+"px";if(mf!=null){mf.style.left=(ww>1004?249+wd:249)+"px";}};function fnCloseMainTooltip(){jq("#main-tooltip").add("#main-tooltip-faux").hide();jq(window).unbind("resize",fnAdjustMainTooltip);};function fnGetPageHeight(){var h=0;if(window.innerHeight&&window.scrollMaxY){h=window.innerHeight+window.scrollMaxY;}else if(document.body.scrollHeight>document.body.offsetHeight){h=document.body.scrollHeight;}else{h=document.body.offsetHeight;}return h;};function fnGetPageHeights(){var h=0;if(window.innerHeight&&document.body.clientHeight){h=window.innerHeight>document.body.clientHeight?window.innerHeight:document.body.clientHeight;}else if(document.documentElement){h=document.documentElement.clientHeight>document.body.clientHeight?document.documentElement.clientHeight:document.body.clientHeight;}return h;};function fnGetPageWidth(){return browser.isSafari?document.body.clientWidth:jq(window).width();};function fnFixOverlay(){jq("#overlay").width(fnGetPageWidth());jq("#overlay").height(fnGetPageHeight());var o1=jq("#overlay1-content-frame").css("top")!="-9999px";var w=o1?jq("#overlay1-content-frame").width():jq("#overlay-content").width();var left=Math.round(((jq(window).width()-w)/2)+jq(window).scrollLeft());if(o1){jq("#overlay1-content-frame").css("left",left);}else{jq("#overlay-content").css("left",left);}if(!o1){var minheight=(parseInt(jq("#overlay-content").css("top"))*2)+jq("#overlay-content").height();if(jq("#overlay").height()<minheight){jq("#overlay").height(minheight);jq("#content").height(minheight);}}};function fnCloseOverlay(){if(browser.isIE6x){jq("select").show();}jq("#overlay-content-iframe").removeClass("fixed");jq("#overlay-content").stop().hide().html("");jq("#overlay1-content").stop().html("");jq("#overlay1-content-frame").removeClass("fixed").removeClass('details-page');jq("#overlay").stop().fadeOut("normal",function(){jq("#content").height("auto");});jq(window).unbind("resize",fnFixOverlay);};function fnShowPageInOverlay(url,isNew,callback){if(typeof isNew!="undefined"){var htmlSrc=url;if(/^\/d\/[^\.]+\-[0-9]+c\//.test(url)){htmlSrc='<iframe src="'+htmlSrc+'" width="618" height="500" frameBorder="0"></iframe>';}}if(jq(window).scrollTop()>0){jq(jq.browser.safari?'body':'html').stop().animate({scrollTop:0},300,"swing",function(){if(typeof isNew!="undefined"){fnShowPageInNewOverlay(htmlSrc,callback);}else{fnShowPageInOverlayCallback(url);}});}else{if(typeof isNew!="undefined"){fnShowPageInNewOverlay(htmlSrc,callback);}else{fnShowPageInOverlayCallback(url);}}};function fnShowPageInOverlayCallback(url){jq(window).scrollTop(0);jq("#overlay-content").height(500);jq("#overlay-content-iframe").removeClass("fixed");jq("#overlay").stop().css({display:"block",width:fnGetPageWidth(),height:fnGetPageHeight(),opacity:0}).animate({opacity:0.5},300,"swing",function(){jq("#overlay").unbind("click");if(browser.isIE6x){jq("select").hide();}fnFixOverlay();jq(window).resize(fnFixOverlay);jq("#overlay-content").show().html("<iframe id=\"overlay-content-iframe\" src=\""+url+"\" width=\"730\" height=\"500\" frameBorder=\"0\" border=\"0\" scrolling=\"no\" />");jq("#overlay-content-iframe").load(function(){var iframe=this;var iheight=iframe.contentWindow.document.body.clientHeight;jq("#overlay-content").stop().animate({height:iheight},"swing",function(){jq(iframe).addClass("fixed").attr("height",iheight);fnFixOverlay();});});jq("#overlay").bind("click",fnCloseOverlay);});};function fnShowPageInNewOverlay(htmlSrc,callback){if(jq("#overlay").css("display")!="none"){fnShowPageInNewOverlayCallback(htmlSrc,callback);}else{jq("#overlay").stop().css({display:"block",width:fnGetPageWidth(),height:fnGetPageHeight(),opacity:0}).animate({opacity:0.5},300,"swing",function(){fnShowPageInNewOverlayCallback(htmlSrc,callback);});}};function fnChangeDetailsOverlay(_href){jq(jq.browser.safari?'body':'html').stop().animate({'scrollTop':0},300,"swing",function(){jq('#overlay1-content').height(250).html('<iframe src="'+_href+'" width="618" height="250" frameBorder="0"></iframe>');});};function fnShowPageInNewOverlayCallback(htmlSrc,callback){var _isDetailsPage=false;if(/\/d\/[^\.]+\-[0-9]+c\//.test(htmlSrc)){_isDetailsPage=true;}var newHtmlSrc="";newHtmlSrc+="<div id=\"overlay1-closebtn\" onclick=\"fnCloseOverlay();\"></div>";newHtmlSrc+="<div id=\"overlay1-content\">"+htmlSrc+"</div>";jq('#overlay1-content-frame').html(newHtmlSrc).addClass("fixed");jq("#overlay").unbind("click");if(_isDetailsPage){jq('#overlay1-content-frame').addClass('details-page');}if(browser.isIE6x){jq("select").hide();jq("#overlay select").add("#overlay1-content-frame select").show();}fnFixOverlay();jq(window).resize(fnFixOverlay);jq("#overlay").bind("click",fnCloseOverlay);if(typeof callback=="function"){callback.apply();}};function fnBroadcastHeight(iheight){if('block'==jq('#overlay1-content-frame').css('display')){var iframe=jq('#overlay1-content-frame iframe');iframe.unbind('load');jq('#overlay1-content').css('height',iheight);jq(iframe).attr('height',iheight);fnFixOverlay();}else{var iframe=jq("#overlay-content-iframe");iframe.unbind("load");jq("#overlay-content").stop().animate({height:iheight},"swing",function(){jq(iframe).addClass("fixed").attr("height",iheight);fnFixOverlay();});}};function fnFeedback(){top.location.href='/feedback/';};function fnTellAFriend(){fnShowPageInOverlay("/refer.jsp");};function fnOpenLink(_url,_fullwidth){var _pd=fnGetPageSize();var _h=_pd.height;var _w=_pd.width;if(!_fullwidth)_w=_w*0.8;_w=window.open(_url,"","height="+_h+", width="+_w+", status=1, toolbar=1, location=1, menubar=1, resizable=1, scrollbars=1, directories=1");if(!_w)window.location.href=_url;_w.focus();};function fnGetPageSize(){var _w=0;var _h=0;if(window.innerHeight&&window.scrollMaxY){_w=window.innerWidth+window.scrollMaxX;_h=window.innerHeight+window.scrollMaxY;}else if(document.body.scrollHeight>document.body.offsetHeight){_w=document.body.scrollWidth;_h=document.body.scrollHeight;}else{_w=document.body.offsetWidth;_h=document.body.offsetHeight;}return{width:_w,height:_h}};String.prototype.getFirstAlphaIndex=function(){var temp=this.split("");for(var i=0;i<temp.length;i++){if("0123456789".indexOf(temp[i])== -1){return i;}}return-1;};function fnActivateCardTpl(cardTpl){jq(cardTpl).find(".search-cardtpl-actions").css({position:"relative"});};function fnNextNearest(value,number){if(value-Math.floor(value)==0.25){return Math.floor(value);}var ceil=Math.ceil(value);var remainder=value%number;if(remainder>0){value=value-remainder+number;}return value;};function fnAddToRecentlyViewedCardsHistory(_id){if(_id<=0)return;var _arr=[];_arr.push(_id);for(var _i=1;_i<6;_i++){var _val=fnReadCookie("rvc-"+_i);if(_arr.length>=5||_val==null)break;if(_val!=_id){_arr.push(_val);}}for(var _i=0;_i<_arr.length;_i++){fnCreateCookie("rvc-"+(_i+1),_arr[_i],7,false);}};function fnCreateCookie(_name,_value,_length,_hours){var _expires="";if(_length!=null){var _date=new Date();_length=(_hours?_length:(24*_length))*60*60*1000;_date.setTime(_date.getTime()+_length);_expires="; expires="+_date.toGMTString();}document.cookie=_name+"="+_value+_expires+"; path=/";};function fnReadCookie(_name){var _nameEQ=_name+"=";var _ca=document.cookie.split(';');for(var _i=0;_i<_ca.length;_i++){var _c=_ca[_i];while(_c.charAt(0)==' ')_c=_c.substring(1,_c.length);if(_c.indexOf(_nameEQ)==0)return _c.substring(_nameEQ.length,_c.length);}return null;};function fnAddOid2Cookie(_id){_id=parseInt(_id);if(isNaN(_id))return;var _val=fnReadCookie("__ch_oid");if(_val==null||_val==""){_val=[];}else{_val=unescape(_val);_val=_val.split(",",20);}if(!fnInArray(_id,_val)){_val.push(_id);if(_val.length>20)_val=_val.slice(_val.length-20);fnCreateCookie("__ch_oid",escape(_val.join(",")));}};function fnInArray(_id,_arr){for(_i=0;_i<_arr.length;_i++){if(_id==_arr[_i])return true;}return false;} 
