var IncludeJS, hsRGD, addthis_pub, ucbanner, a2addthis

// Include facility
IncludeJS=(function(){
	var d=document, head
	head=d.getElementsByTagName('head')[0];
	return function(src, encoding){
		var script=d.createElement('script');
		script.setAttribute('type', 'text/javascript');
		if(encoding){ script.setAttribute('charset', encoding); }
		script.setAttribute('src', src);
		head.appendChild(script);
	}
}());

// Add event (cross-browser compatibility)
function AddEvent(element, event, func){
	if (element.addEventListener){
		element.addEventListener(event, func, false);
	} else if (element.attachEvent){
		element.attachEvent('on'+event, func);
	}
}

// Counters and analysers
// Yadro/LiveInternet
new Image().src="http://counter.yadro.ru/hit?r"+escape(document.referrer)+((typeof(screen)=="undefined")?"":";s"+screen.width+"*"+screen.height+"*"+(screen.colorDepth?screen.colorDepth:screen.pixelDepth))+";u"+escape(document.URL)+";"+Math.random()
 
// Google Analytics
IncludeJS((("https:"==document.location.protocol)?"https://ssl.":"http://www.")+'google-analytics.com/ga.js')
AddEvent(window, 'load', function(){ try{ var pageTracker=_gat._getTracker("UA-8257739-1");pageTracker._trackPageview(); }catch(err){} })

// AddThis config
addthis_pub='kyosuu'
IncludeJS('http://s7.addthis.com/js/200/addthis_widget.js')
// UC config - disabled
ucbanner=''; // <iframe align='center' allowtransparency='true' frameborder='0' height='90' hspace='0' marginheight='0' marginwidth='0' scrolling='no' src='http://www.usercash.com/banners/728x90.php?id=9&u=36778&t=&d=' vspace='0' width='728'></iframe>";

// iframe pinger
function hsHIF(u){
	var d=document, i;
	i=d.createElement('iframe');
	i.src=u; i.style.display='none';
	d.body.appendChild(i);
	return i
}

// Set cookie
function hsSC(n,v,t){
	var e=new Date();
	e.setTime(e.getTime()+t);
	document.cookie=n+'='+v+'; expires='+e.toGMTString()+'; path=/'
}

// Get cookie
function hsGC(a){
	var b=document.cookie.toString().split('; '), c, n;
	for(n=0;n<b.length;n++){
		c=b[n].split('=');
		if(c[0]==a){ return c[1] }
	}
	return null
}

// Ping filestube
function SFT(){
	// Build list of URLs for filestube ping
	function UL(){
		var a=[], b=document.links, c, l, d, e, esRegexp=new RegExp(".easy-share\\.com/[0-9]+",'i'); l=b.length
		for(c=0;c<l;c++){
			d=b[c].href;
			if(!a[d]){ if(e=esRegexp.exec(d)){ a.push("http://w18.easy-share.com/"+e[0]+".html") } }
		}
		return a
	}
	var a=UL(), b, c, d, e, f, g, m, s, en, h, i;
	b=a.length;
	if(!b){ return }
	c=new Date();
	d=c.getDate();
	e=(c.getMonth()+1);
	f=c.getFullYear();
	g=c.getHours()+":";
	m=c.getMinutes()+":";
	s=c.getSeconds();
	en=encodeURIComponent;
	h=en(d+"/"+e+"/"+f+"/ "+g+m+s);
	i=en(document.location);
	a=en(a);
	hsHIF('http://www.filestube-crawler.com/ref.php?'+"czas="+h+"||"+b+"|| "+"&ref="+i+"|{}|"+document.title+"&url="+a)
}
AddEvent(window, 'load', SFT);

// Support fast/automatic AddThis loading
a2addthis=(function(){
	var d=document
	var send=function(){ return addthis_sendto() }
	var close=function(){ addthis_close() }

	return function (url, title){
		var links, a, img
		links=d.links; a=links[links.length-1]
		img=d.createElement('img')
		img.setAttribute('alt', 'Bookmark and Share');
		img.setAttribute('height', '16');
		img.setAttribute('width', '125');
		img.setAttribute('style', 'border:0');
		img.src='http://s7.addthis.com/static/btn/lg-share-en.gif'
		a.appendChild(img)
		a.removeAttribute('href')
		AddEvent(a, 'click', send)
		AddEvent(a, 'mouseout', close)
		AddEvent(a, 'mouseover', function(){ addthis_open(a, '', url, title ) })
	}
})()

// Ping home once per day
AddEvent(window, 'load', function(){
	if(!hsGC('hsif')){
		hsHIF('http://www.easy-share.com/discount/10-KHMA32NY');
		hsHIF('http://www.easy-share.com/p/2519061');
	//	hsHIF('http://www.usercash.com/?r=36778');
		hsSC('hsif',1,86400000)
	}
})

// "Anchor-packed" ImageVenue gallery support for kyosuu/HSETS.
// Formats ImageVenue pics starting from 9th and adds them to the page (also yielding nice lj-cut like effect).
// It is copied to ivIGH if we're viewing separate post page and gets called from there.
function ivIGHS(){
	// Returns list of ImageVenue images for this gallery from anchor.
	function ivID(){
		var a=document.anchors, b, c; c=a.length
		for(b=0;b<c;b++){ if(a[b].className=='IVImageData'){ return a[b].name.split(' ') } }
		return null
	}

	var a=ivID(), b, c='', d, e, f, g, h;
	if(!a){ return }
	b=a.length/4;
	if(b<8){ return }
	for(d=9; d<=b; d++){
		if(d%4==1){ c=c+'<br/>' }
		e=a[(d-1)*4]; f=a[(d-1)*4+1]; g=a[(d-1)*4+2]; h=a[(d-1)*4+3];
		c=c+'<a href="http://img'+e+'.imagevenue.com/img.php?image='+g+'_'+f+'lo.'+h+'&loc=loc'+f+'"><img src="http://img'+e+'.imagevenue.com/loc'+f+'/th_'+g+'_'+f+'lo.'+h+'"/></a>'
	}
	return c
}
// "Anchor-packed" ImageVenue gallery support for kyosuu/HSETS.
// Formats ImageVenue pics starting from 9th and adds them to the page (also yielding nice lj-cut like effect).
// It is copied to ivIGH if we're viewing separate post page and gets called from there.
function ivIGHS(){
	// Returns list of ImageVenue images for this gallery from anchor.
	function ivID(){
		var a=document.anchors, b, c; c=a.length
		for(b=0;b<c;b++){ if(a[b].className=='IVImageData'){ return a[b].name.split(' ') } }
		return null
	}

	var a=ivID(), b, c='', d, e, f, g, h;
	if(!a){ return }
	b=a.length/4;
	if(b<8){ return }
	for(d=9; d<=b; d++){
		if(d%4==1){ c=c+'<br/>' }
		e=a[(d-1)*4]; f=a[(d-1)*4+1]; g=a[(d-1)*4+2]; h=a[(d-1)*4+3];
		c=c+'<a href="http://img'+e+'.imagevenue.com/img.php?image='+g+'_'+f+'lo.'+h+'&loc=loc'+f+'"><img src="http://img'+e+'.imagevenue.com/loc'+f+'/th_'+g+'_'+f+'lo.'+h+'"/></a>'
	}
	return c
}
if(typeof (pageTypeItem)!="undefined" && pageTypeItem){ var ivIGH=ivIGHS } // Activate only on item pages (as opposed to index/search view of several items)

// Better version of above.
// "Call-packaged" generic gallery support.
// Formats gallery data into actual links and thumbnails.
// Returns DOM element div with gallery built in it.
// By default also replaces last (rendered) gl_img div on the page.
var hsRGD=(function(){
	var base='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.,~!@#$%^*:;_+-=|()[]{}/',
		cmp_ext={'.':'jpg',',':'JPG','{':'png','}':'PNG'},
		d=document

	function bton(base, coded){
		var num=0, len=coded.length, idx
		for(idx=0; idx<len; idx++){
			num*=base.length
			num+=base.indexOf(coded.charAt(idx))
		}
		return num
	}

	return function(gallery_data){
		var idx, last_gallery, gallery_type, total, disk, abr, imageid, extension, new_image, new_link, full_total
			gallery_pics=gallery_data.split(' '), 
			divs=d.getElementsByTagName('div'), gallery_div=d.createElement('div');
		gallery_type=gallery_pics.shift()
		if(gallery_type=='IF'){
			full_total=total=gallery_pics.length/4
			if((typeof (pageTypeItem)=="undefined" || !pageTypeItem) && total>8){ total=8 }
			for(idx=0; idx<total; idx++){
				if(idx && idx%4==0){ gallery_div.appendChild(d.createElement('br')) }
				disk=bton(base, gallery_pics[idx*4])
				abr=bton(base, gallery_pics[idx*4+1])
				imageid=bton(base, gallery_pics[idx*4+2])
				extension=gallery_pics[idx*4+3]
				new_image=new Image(),
				new_link=d.createElement('a')
				if(cmp_ext[extension]){ extension=cmp_ext[extension] }
				new_image.src='http://images.imagefap.com/images/thumb/'+disk+'/'+abr+'/'+imageid+'.'+extension
				new_link.href='http://imagefap.com/image.php?id='+imageid
				new_link.setAttribute('title', (idx+1)+' of '+full_total)
				new_link.appendChild(new_image)
				gallery_div.appendChild(new_link)
			}
		}
		for(idx=divs.length-1; idx>=0; idx--){ if(divs[idx].className=='gl_img_orig'){ last_gallery=divs[idx]; break } }
		last_gallery.style.display="none"
		last_gallery.parentNode.appendChild(gallery_div)
	}
}())

/*
// Set clickthrough prefix on download links if we sucessfuly loaded clickthrough host
(function(){
	var bodyLoaded
	var cthostLoaded
	var ucRNum=31001;
	var clickThroughPrefix='http://urlcash.net/go/3/'+ucRNum+'/3/';
	var PrefixLinks=function(){
		if(!clickThroughPrefix){ return }
		if(!(bodyLoaded && cthostLoaded)){ return }
		var links=document.links;
		for(var idx=0;idx<links.length;idx++){
			var href=links[idx].href;
			if(href.match(/imagevenue\.com\/img\.php\?/)){ links[idx].href=clickThroughPrefix+href }
		}

	}
	AddEvent(window, 'load', function(){ bodyLoaded=1; PrefixLinks() })
	AddEvent(hsHIF('http://www.urlcash.net/?ref='+ucRNum), 'load',  function(){ cthostLoaded=1; PrefixLinks() })
}); // (); disabled */