/** JSON **/
(function($){var m={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'},s={'array':function(x){var a=['['],b,f,i,l=x.length,v;for(i=0;i<l;i+=1){v=x[i];f=s[typeof v];if(f){v=f(v);if(typeof v=='string'){if(b){a[a.length]=',';}
a[a.length]=v;b=true;}}}
a[a.length]=']';return a.join('');},'boolean':function(x){return String(x);},'null':function(x){return"null";},'number':function(x){return isFinite(x)?String(x):'null';},'object':function(x){if(x){if(x instanceof Array){return s.array(x);}
var a=['{'],b,f,i,v;for(i in x){v=x[i];f=s[typeof v];if(f){v=f(v);if(typeof v=='string'){if(b){a[a.length]=',';}
a.push(s.string(i),':',v);b=true;}}}
a[a.length]='}';return a.join('');}
return'null';},'string':function(x){if(/["\\\x00-\x1f]/.test(x)){x=x.replace(/([\x00-\x1f\\"])/g,function(a,b){var c=m[b];if(c){return c;}
c=b.charCodeAt();return'\\u00'+
Math.floor(c/16).toString(16)+
(c%16).toString(16);});}
return'"'+x+'"';}};$.toJSON=function(v){var f=isNaN(v)?s[typeof v]:s['number'];if(f)return f(v);};$.parseJSON=function(v,safe){if(safe===undefined)safe=$.parseJSON.safe;if(safe&&!/^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/.test(v))
return undefined;return eval('('+v+')');};$.parseJSON.safe=false;})(jQuery);
/** CookieJar **/
(function($){$.cookieJar=function(name,options){if(!$.parseJSON)return false;if(!$.toJSON)return false;if(!$.cookie)return false;return new function(){function log(s){if(typeof console!='undefined'&&typeof console.log!='undefined'){console.log('cookiejar:'+self.cookieName+' '+s);}else{alert(s);}};function save(){if(self.options.debug)log('save '+$.toJSON(self.cookieObject));return $.cookie(self.cookieName,$.toJSON(self.cookieObject),self.options.cookie);};function load(){var cookieJSON=$.cookie(self.cookieName);if(typeof cookieJSON=='string'){if(self.options.debug)log('load '+cookieJSON);self.cookieObject=$.parseJSON(cookieJSON,true);}else{if(self.options.debug)log('load new');self.cookieObject={};save();}}
this.set=function(name,value){if(self.options.debug)log('set '+name+' = '+value);self.cookieObject[name]=value;return save();};this.get=function(name){if(!self.options.cacheCookie){load();}
if(self.options.debug)log('get '+name+' = '+self.cookieObject[name]);return self.cookieObject[name];};this.remove=function(name){if(self.options.debug)log('remove '+name);if(typeof name!='undefined'){delete(self.cookieObject[name]);}else{self.setFromObject({});}
return save();};this.setFromObject=function(object){if(typeof object=='object'){if(self.options.debug)log('setFromObject');self.cookieObject=object;return save();}};this.toObject=function(){if(self.options.debug)log('toObject');return self.cookieObject;};this.toString=function(){if(self.options.debug)log('toString = '+$.toJSON(self.cookieObject));return $.toJSON(self.cookieObject);};this.destroy=function(){if(self.options.debug)log('destroy');self.cookieObject={};return $.cookie(self.cookieName,null,self.options.cookie);};this.construct=function(name,options){self.options=$.extend({cookie:{expires:365,path:'/'},cacheCookie:true,cookiePrefix:'jqCookieJar_',debug:false},options);self.cookieName=self.options.cookiePrefix+name;load();return self;};var self=this;self.construct(name,options);};};})(jQuery);
/** Cookie **/
jQuery.cookie=function(name,value,options){if(typeof value!='undefined'){options=options||{};if(value===null){value='';options.expires=-1;}
var expires='';if(options.expires&&(typeof options.expires=='number'||options.expires.toUTCString)){var date;if(typeof options.expires=='number'){date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*1000));}else{date=options.expires;}
expires='; expires='+date.toUTCString();}
var path=options.path?'; path='+options.path:'';var domain=options.domain?'; domain='+options.domain:'';var secure=options.secure?'; secure':'';document.cookie=[name,'=',encodeURIComponent(value),expires,path,domain,secure].join('');}else{var cookieValue=null;if(document.cookie&&document.cookie!=''){var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+'=')){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break;}}}
return cookieValue;}};
// gaTracker: jQuery Google Analytics Integration // A quicker, automated way to embed Google Analytics. // (c)2007 Jason Huck/Core Five Creative
(function($){$.gaTracker=function(code,opts){opts=jQuery.extend({external:'/external/',mailto:'/mailtos/',download:'/downloads/',extensions:['pdf','doc','xls','csv','jpg','gif','mp3','swf','txt','ppt','zip','gz','dmg','xml']},opts);function decorateLink(u){var trackingURL='';if(u.indexOf('://')==-1&&u.indexOf('mailto:')!=0){var ext=u.split('.')[u.split('.').length-1];var exts=opts.extensions;for(i=0;i<exts.length;i++){if(ext==exts[i]){trackingURL=opts.download+u;break;}}}else{if(u.indexOf('mailto:')==0){trackingURL=opts.mailto+u.substring(7);}else{var regex=/([^:\/]+)*(?::\/\/)*([^:\/]+)(:[0-9]+)*\/?/i;var linkparts=regex.exec(u);var urlparts=regex.exec(location.href);if(linkparts[2]!=urlparts[2])trackingURL=opts.external+u;}}
return trackingURL;}
function addTracking(){_uacct=code;urchinTracker();$('a').each(function(){var u=$(this).attr('href');if(typeof(u)!='undefined'){var newLink=decorateLink(u);if(newLink.length){$(this).click(function(){urchinTracker(newLink);});}}});}
function initGA(){try{var gaURL=(location.href.indexOf('https')==0?'https://ssl':'http://www');gaURL+='.google-analytics.com/urchin.js';$.getScript(gaURL,function(){addTracking();});}catch(err){console.log('Failed to load Google Analytics:'+err);}}
initGA();}})(jQuery);
/** HoverIntent + Accordion **/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);
(function($){$.fn.hoverAccordion=function(options){options=jQuery.extend({speed:'fast',activateitem:'true',active:'active',header:'header',hover:'hover',opened:'opened',closed:'closed',keepheight:'true'},options);thislist=this;var thisurl=window.location.href;function doHover(obj){if($(obj).html()==undefined)obj=this;if(!thislist.is(':animated')){var newelem=$(obj).parent().children('ul');var oldelem=$(obj).parent().parent().children('li').children('ul:visible');if(options.keepheight=='true'){thisheight=maxheight}else{thisheight=newelem.height()}if(!newelem.is(':visible')){if(!oldelem.length>0){newelem.animate({height:thisheight},{duration:options.speed,easing:'linear'})}else{newelem.show()}oldelem.animate({height:'hide'},{step:function(n,fx){newelem.height(thisheight-n)},duration:options.speed,easing:'linear'});oldelem.parent().children('a').addClass(options.closed).removeClass(options.opened);newelem.parent().children('a').addClass(options.opened).removeClass(options.closed)}}};function doNothing(){};var itemNo=0;var maxheight=0;$(this).children('li').each(function(){var thisitem=$(this);itemNo++;var thislink=thisitem.children('a');if(thislink.length>0){thislink.hover(function(){$(this).addClass(options.hover)},function(){$(this).removeClass(options.hover)});var thishref=thislink.attr('href');if(thishref=='#'){thislink.click(function(){doHover(this);this.blur();return false})}else if(options.activateitem=='true'&&thisurl.indexOf(thishref)>0&&thisurl.length-thisurl.lastIndexOf(thishref)==thishref.length){thislink.parent().addClass(options.active)}}var thischild=thisitem.children('ul');if(thischild.length>0){if(maxheight<thischild.height())maxheight=thischild.height();thischild.children('li.'+options.active).parent().parent().children('a').addClass(options.header);try{thislink.hoverIntent({sensitivity:1,interval:80,over:doHover,timeout:600,out:doNothing})}catch(err){thislink.hover(function(){doHover(this)},function(){doNothing()})}if(options.activateitem=='true'){thischild.children('li').each(function(){var m=$(this).children('a').attr('href');if(m){if(thisurl.indexOf(m)>0&&thisurl.length-thisurl.lastIndexOf(m)==m.length){$(this).addClass(options.active).parent().parent().children('a').addClass(options.opened)}}})}else if(parseInt(options.activateitem)==itemNo){thisitem.addClass(options.active).children('a').addClass(options.opened)}}thischild.not($(this).parent().children('li.'+options.active).children('ul')).not(thischild.children('li.'+options.active).parent()).hide().parent().children('a').addClass(options.closed)});return this}})(jQuery);
/** RememberBox **/
function dogEarBox(){this.cookies=$.cookieJar('dogEar');this.dogEars=this.cookies.get('dogEars');if(typeof this.dogEars!='object'||this.dogEars.constructor!=Array){this.dogEars=[];}
this.updateCount=function(){$('div#dogearbox h4').text('Your Bookmarks');}
this.dogEarListItem=function(dogEar){if(document.getElementById('dogEarLink-'+dogEar.id))
return $('#dogEarLink-'+dogEar.id);var li=$('<li id="dogEarLink-'+dogEar.id+'"><a href="'+dogEar.url+'" class="title">'+dogEar.title+'</a><a class="close"><img src="/qc3/gfx/del.gif" /></a></li></ul>');li.find('a.title').attr('title',dogEar.title);var close=li.find('a.close');close.attr('title',dogEar.title);close.click(function(){document.dogEarBox.click(dogEar);});return li;}
for(var i=0;i<this.dogEars.length;i++){var dogEar=this.dogEars[i]
$('#dogear-'+dogEar.id).addClass('folded');this.dogEarListItem(dogEar).appendTo('#dogearbox .dogears');}
this.updateCount();if(this.dogEars.length>0)
$('#dogearbox').show();this.store=function(){this.cookies.set('dogEars',this.dogEars);}
this.click=function(dogEar){if(this.have(dogEar)){this.remove(dogEar);$('#dogear-'+dogEar.id).removeClass('folded');var me=this;if(this.dogEars.length==0){$('#dogearbox').slideUp('fast',function(){me.dogEarListItem(dogEar).remove();});}else{this.dogEarListItem(dogEar).slideUp('fast',function(){me.dogEarListItem(dogEar).remove();});}}else{this.add(dogEar);$('#dogear-'+dogEar.id).addClass('folded');if(this.dogEars.length==1){this.dogEarListItem(dogEar).appendTo('#dogearbox .dogears');$('#dogearbox').slideDown('slow');}else{this.dogEarListItem(dogEar).hide().appendTo('#dogearbox .dogears');this.dogEarListItem(dogEar).slideDown('slow');}}
this.updateCount();this.store();}
this.add=function(dogEar){this.dogEars.push(dogEar);}
this.remove=function(dogEar){this.dogEars.splice(this.indexOf(dogEar),1);}
this.have=function(dogEar){return this.indexOf(dogEar)>=0;}
this.indexOf=function(dogEar){for(var i=0;i<this.dogEars.length;i++){if(this.dogEars[i].id==dogEar.id)
return i;}
return-1;}}
/** Color Animations **/
(function(jQuery){jQuery.each(['backgroundColor','borderBottomColor','borderLeftColor','borderRightColor','borderTopColor','color','outlineColor'],function(i,attr){jQuery.fx.step[attr]=function(fx){if(fx.state==0){fx.start=getColor(fx.elem,attr);fx.end=getRGB(fx.end);}
fx.elem.style[attr]="rgb("+[Math.max(Math.min(parseInt((fx.pos*(fx.end[0]-fx.start[0]))+fx.start[0]),255),0),Math.max(Math.min(parseInt((fx.pos*(fx.end[1]-fx.start[1]))+fx.start[1]),255),0),Math.max(Math.min(parseInt((fx.pos*(fx.end[2]-fx.start[2]))+fx.start[2]),255),0)].join(",")+")";}});function getRGB(color){var result;if(color&&color.constructor==Array&&color.length==3)
return color;if(result=/rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color))
return[parseInt(result[1]),parseInt(result[2]),parseInt(result[3])];if(result=/rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color))
return[parseFloat(result[1])*2.55,parseFloat(result[2])*2.55,parseFloat(result[3])*2.55];if(result=/#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color))
return[parseInt(result[1],16),parseInt(result[2],16),parseInt(result[3],16)];if(result=/#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color))
return[parseInt(result[1]+result[1],16),parseInt(result[2]+result[2],16),parseInt(result[3]+result[3],16)];return colors[jQuery.trim(color).toLowerCase()];}
function getColor(elem,attr){var color;do{color=jQuery.curCSS(elem,attr);if(color!=''&&color!='transparent'||jQuery.nodeName(elem,"body"))
break;attr="backgroundColor";}while(elem=elem.parentNode);return getRGB(color);};var colors={aqua:[0,255,255],azure:[240,255,255],beige:[245,245,220],black:[0,0,0],blue:[0,0,255],brown:[165,42,42],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgrey:[169,169,169],darkgreen:[0,100,0],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkviolet:[148,0,211],fuchsia:[255,0,255],gold:[255,215,0],green:[0,128,0],indigo:[75,0,130],khaki:[240,230,140],lightblue:[173,216,230],lightcyan:[224,255,255],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightyellow:[255,255,224],lime:[0,255,0],magenta:[255,0,255],maroon:[128,0,0],navy:[0,0,128],olive:[128,128,0],orange:[255,165,0],pink:[255,192,203],purple:[128,0,128],violet:[128,0,128],red:[255,0,0],silver:[192,192,192],white:[255,255,255],yellow:[255,255,0]};})(jQuery);
/** Carousel **/
function mycarousel_initCallback(carousel) {
    carousel.buttonNext.bind('click',function(){ carousel.startAuto(0);  });
    carousel.buttonPrev.bind('click',function(){ carousel.startAuto(0); });
	carousel.clip.hover(function() { carousel.stopAuto(); }, function() { carousel.startAuto(); });
};
/** FoldAd **/
function foldthead(high,foo){ if(foo == undefined){ $('#unfolding a').animate({height:high+'em'},500); }else{ window.setTimeout(function(){ $('#unfolding a').animate({height:high+'em'},500); }, foo); }};

/** on PageLoad **/
$(document).ready(function(){
	var domain = 'queerclick.com';
	$.gaTracker('UA-5121746-1');
	
	$('#unfolding a').css({'height':'34em'});
	foldthead(7,7500);
	$('#unfolding a').hover( function () { foldthead(34) }, function () { foldthead(7,5000) } );
	
	document.dogEarBox = new dogEarBox();
	$('#menu').removeClass("nojsmenu");
	$('#searchInput').attr({ value:'Search' });
	$('#newsletter-email').attr({ value:'Enter your Email' });
	//$.ajax({ url:"http://www.queerclick.com/qc3/ajax.html", timeout: 3000, dataType:"html", success:function(data){ $("#ajaxloader").show(data); $('#loadgif').show(); $('#loadgif').hide(); $("#ajaxloader").append(data); } }); // , error:function(xhr,err,e){ $("#ajaxloader").hide(); }
	$('#showlang').click( function() { $('#langch').toggle(); return false; } );

	//$('#sbi, #sbi2').jcarousel({ scroll: 1, animation: 'slow', wrap: 'last', initCallback: mycarousel_initCallback });
	$('#sbi').jcarousel({ scroll: 1, animation: 'slow', wrap: 'last', initCallback: mycarousel_initCallback });
	$('#acc2').hoverAccordion({ activateitem: '1', speed: 'normal', keepheight: 'true' });
	$('.jcarousel-prev-horizontal').append('<img src="http://www.queerclick.com/qc3/gfx/prev.gif" style="width: 1.4em; height: 1.4em;" />');
	$('.jcarousel-next-horizontal').append('<img src="http://www.queerclick.com/qc3/gfx/next.gif" style="width: 1.4em; height: 1.4em;" />');
	
	$('.postcontent img, .postcontent object, .postcontent embed, .searchcontent img, .sbis img, .btmimglist img, #partner img').each(function(){ var lala = $(this).attr("width") / 10; var lulu = $(this).attr("height") / 10; var inserter = "width:"+lala+"em; height: "+lulu+"em;"; $(this).attr({style: inserter}); });
	$('.postcontent a[href^=http://]').filter('[href*="'+domain+'"]').each(function(){ $(this).after('<sup class="qcl">&#9632;</sup>'); });
	$('#adlinks p, #adlinks br').remove();
	$('#adlinks div').addClass('headlike');
	
	$('.menulist a[class!=current]').hover( function () { $(this).animate({ backgroundColor: "#444", borderBottomColor: "#F80" }, 500); }, function () { $(this).animate({ backgroundColor: "#333", borderBottomColor: "#555" }, 1000); } );
	$('.dogear').hover( function () { if($(this).hasClass('folded')) { var dogtext = 'Remove QC Bookmark'; } else { var dogtext = 'Add QC Bookmark'; }; $(this).parent().children(".helper").append(dogtext); }, function () { $(this).parent().children('.helper').empty(); } );
	$('.commentlink').hover( function () { $(this).parent().children(".helper").append('Show Comments'); }, function () { $(this).parent().children('.helper').empty(); } );
	$('.thumblink').hover( function () { $(this).parent().children(".helper").append('Thumbs Up!'); }, function () { $(this).parent().children('.helper').empty(); } );
	$('.permlink').hover( function () { $(this).parent().children(".helper").append('Share'); }, function () { $(this).parent().children('.helper').empty(); } );
	$('.permlink').click( function () {
		var permalinker = $(this).attr("href");
		var permlinktitle = encodeURI($(this).parents('div:has(h2)').find("h2 a").html());
		var sharelinks = '<a href="http://digg.com/submit?phase=2&amp;url=' + permalinker + '"><img src="http://www.queerclick.com/qc3/gfx/icn-digg.png" style="width:1.335em;height:1.335em;" height="16" width="16" /></a>' +
		'<a href="http://del.icio.us/post?url=' + permalinker + '&amp;title=' + permlinktitle + '"><img src="http://www.queerclick.com/qc3/gfx/icn-delicious.png" style="width:1.335em;height:1.335em;" height="16" width="16" /></a>' +
		'<a href="http://www.facebook.com/share.php?u=' + permalinker + '"><img src="http://www.queerclick.com/qc3/gfx/icn-facebook.png" style="width:1.335em;height:1.335em;" height="16" width="16" /></a>' +
		'<a href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=' + permalinker + '&amp;title=' + permlinktitle + '"><img src="http://www.queerclick.com/qc3/gfx/icn-google.png" style="width:1.335em;height:1.335em;" height="16" width="16" /></a>' +
		'<a href="http://reddit.com/submit?url=' + permalinker + '&amp;title=' + permlinktitle + '"><img src="http://www.queerclick.com/qc3/gfx/icn-reddit.gif" style="width:1.335em;height:1.335em;" height="16" width="16" /></a>' +
		'<a href="http://www.stumbleupon.com/submit?url=' + permalinker + '"><img src="http://www.queerclick.com/qc3/gfx/icn-stumble.png" style="width:1.335em;height:1.335em;" height="16" width="16" /></a>' + 
		'<form style="display: inline; margin: -.5em 0 0 .5em; padding: 0;"><input style="margin: 0; width: 30em; font-size: .8em;" class="name_text" value="' + permalinker + '" /></form>';
		$(this).parents('div').children('.share').html(sharelinks);
		$(this).parents('div').children('.share').slideToggle();
		return false;
	} );
	$('.dogear').click( function () { var dogid = $(this).attr("id"); var getdognumber = /(\w.+)-(\w.+)/; getdognumber.exec(dogid); var realid = RegExp.$2; var dogeartitle = $(this).parents('div:has(h2)').find("h2 a").html(); var permalinker = encodeURI($(this).parent().children(".permlink").attr("href")); document.dogEarBox.click({"id":realid,"title":dogeartitle,"url":permalinker}); if($(this).hasClass('folded')) { $(this).parents('.postsub').animate({ backgroundColor: "#360" }, 50).animate({ backgroundColor: "#555" }, 1000); } else { $(this).parents('.postsub').animate({ backgroundColor: "#600" }, 50).animate({ backgroundColor: "#555" }, 1000); }; return false; } );

	$('#searchInput').focus( function () { $(this).addClass('searchactive'); $(this).filter('[value*="Search"]').attr({ value:'' }); }).blur(function() { $(this).removeClass('searchactive'); $(this).filter('[value=""]').attr({ value:'Search' }); });
	$('#newsletter-email').focus( function () { $(this).addClass('searchactive'); $(this).filter('[value*="Enter your Email"]').attr({ value:'' }); }).blur(function() { $(this).removeClass('searchactive'); $(this).filter('[value=""]').attr({ value:'Enter your Email' }); });
});