 $(document).ready(function(){

$('#boobs').click(function(){
	if ($("input[@name='selectCountry']:checked").val() == 'Europe'){
		$('#shipping').val('0');
		$('#verzendkosten').text('0');
		alert('No more shipping costs for Europeans! (In case of banktransfer, subtract 4 euro\'s yourself');
	}
});

$('#menu').bind('click',function(){
	top.location.href='index.php';
});

var settings = {
			'transitionIn'	:	'elastic',
			'transitionOut'	:	'elastic',
			'speedIn'		:	500, 
			'speedOut'		:	500, 
			'overlayShow'	:	true,
			'overlayOpacity'	: 0.85,	
			'overlayColor'	:	'#7EA43D'
						}

jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        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(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        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 { // only name given, get cookie
        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]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};


//resize function
(function($) {
    $.fn.resize = function(options) {
 
        var settings = $.extend({
            scale: 1,
            maxWidth: null,
			maxHeight: null
        }, options);
 
        return this.each(function() {
			
			if(this.tagName.toLowerCase() != "img") {
				// Only images can be resized
				return $(this);
			} 

			var width = this.naturalWidth;
			var height = this.naturalHeight;
			if(!width || !height) {
				// Ooops you are an IE user, let's fix it.
				var img = document.createElement('img');
				img.src = this.src;
				
				width = img.width;
				height = img.height;
			}
			
			if(settings.scale != 1) {
				width = width*settings.scale;
				height = height*settings.scale;
			}
			
			var pWidth = 1;
			if(settings.maxWidth != null) {
				pWidth = width/settings.maxWidth;
			}
			var pHeight = 1;
			if(settings.maxHeight != null) {
				pHeight = height/settings.maxHeight;
			}
			var reduce = 1;
			
			if(pWidth < pHeight) {
				reduce = pHeight;
			} else {
				reduce = pWidth;
			}
			
			if(reduce < 1) {
				reduce = 1;
			}
			
			var newWidth = width/reduce;
			var newHeight = height/reduce;
			
			return $(this)
				.attr("width", newWidth)
				.attr("height", newHeight);
			
        });
    }
})(jQuery);

function imgswap(idz,img1,img2){
	var ida = $("#"+idz);
	ida.css('background-image','url(design_img/'+img1+')');
	ida.html('');
	ida.prepend("<div style='position:relative;'><img src='design_img/"+img2+"' style='border:0;position:absolute;left:0px;top:0px;' id='ro_"+idz+"'/></div>");
	$('#ro_'+idz).css('opacity',0);
	var idabef = ida.css("background-image");
	ida.hover(function(){
						   if (jQuery.browser.msie) {
							   ida.css("background-image",'url(design_img/'+img2+')');
						   }else{
								$('#ro_'+idz).animate({'opacity':1});
						   }
					   },function(){
						   if (jQuery.browser.msie) {
							   ida.css("background-image",idabef);
						   }else{						   
								$('#ro_'+idz).animate({'opacity':0});
						   }
						});
}

/*
 * jQuery longUrl - v1.0 - 1/23/2010
 * http://benalman.com/projects/jquery-longurl-plugin/
 * 
 * Copyright (c) 2010 "Cowboy" Ben Alman
 * Dual licensed under the MIT and GPL licenses.
 * http://benalman.com/about/license/
 */
(function($,e){var a={},c,b,d={fetch:function(f,g){$.ajax({dataType:"jsonp",traditional:1,url:"http://www.longurlplease.com/api/v1.1",data:{q:f},success:g})},batch:10};$.longUrl=c=function(j,k){var f={},g=0;if(Object.prototype.toString.call(j)==="[object Object]"){b=$.extend({},d,j);return}j=typeof j==="string"?[j]:j;(function h(){var i=[],l;while(g<j.length&&i.length<b.batch){l=j[g++];if(!l||!/^https?:\/\//i.test(l)){continue}if(a[l]!==e){f[l]=a[l]}else{if($.inArray(l,i)===-1){i.push(l)}}}if(i.length){b.fetch(i,function(m){$.each(m,function(n,o){f[n]=a[n]=o});h()})}else{k(f)}})()};c({});$.fn.longUrl=function(g){var h=this,f={},j=[],i={callback:function(k,l){if(l){this.each(function(){var n=$(this),m=n.html();n.attr({title:l,href:l});if(n.html()!==m){n.html(m)}})}}};g=$.extend(i,g);this.each(function(){var l=$(this),k=l.attr("href");if(k){f[k]=f[k]?f[k].add(this):l;j.push(k)}});c(j,function(k){g.callback&&$.each(k,function(l,m){if(f[l]){g.callback.call(f[l],l,m);delete f[l]}});f=null;g.complete&&g.complete.call(h,k)});return this}})(jQuery);


//comics============================================================================================
var ci = $('#comicimg');
ci.animate({opacity:'show'},500);

$('#menu a').hover(function(){$(this).css({'color':'#FFF',top:'-2px'})},
				   function(){$(this).css({'color':'#c4da98',top:'0px'})}
				   );
var $nummerlang;
var epi = $nummerlang;
var numm = $('#nummer');
var nb = $('#nummerbig');
nb.hide();
var numval = numm.text();

if (numval.length == 1){
	numval = '00'+numval;
}else if(numval.length == 2){
	numval = '0'+numval;	
}

for (x=0; x < numval.length; x++){
	xe = x + 1;
	var xb = (numval.charAt(x));
	$('#num'+xe+'a').css('background-image','url(design_img/'+xb+'.png)');
	$('#num'+xe+'b').css({
								'background-image':'url(design_img/'+xb+'.png)',
								'background-position':'0 -68px'
								});	
	$('#num'+xe+'a').attr('id2',xb);
	$('#num'+xe+'b').attr('id2',xb);	
}
$('#numgo').css({
					 'background-image':'url(design_img/go.png)',
					 'background-repeat':'no-repeat'
					 });

function plusone(n){
	var nu = n*1;
	nu = nu + 1;
	if (nu == 10) {nu = 0};
	return nu;
}
function minusone(n){
	var nu = n*1;	
	nu = nu - 1;
	if (nu == -1)  nu = 9;
	return nu;
}

$('.topnum').click(function(){
						var curnum = $(this).attr("id2");
						var nb = $(this).attr("id").replace('num','').replace('a','');
						var newnum = plusone(curnum);
						$(this).attr('id2',newnum);
						$(this).css(
									  'background-image','url(design_img/'+newnum+'.png)'
									  );
						$('#num'+nb+'b').attr('id2',newnum);
						$('#num'+nb+'b').css(
									  'background-image','url(design_img/'+newnum+'.png)'
									  );
						return false;
});

$('.botnum').click(function(){
						var curnum = $(this).attr("id2");
						var nb = $(this).attr("id").replace('num','').replace('b','');
						var newnum = minusone(curnum);
						$(this).attr('id2',newnum);
						$(this).css(
									  'background-image','url(design_img/'+newnum+'.png)'
									  );
						$('#num'+nb+'a').attr('id2',newnum);
						$('#num'+nb+'a').css(
									  'background-image','url(design_img/'+newnum+'.png)'
									  );	
						return false;
});

var vgo = $('#numgo');
vgo.click(function(){
				 document.location.href='index.php?max='+$('#max').attr('value')+'&wltypeid='+$('#wltypeid').attr('value')+'&episode='+$('#num1a').attr('id2')+$('#num2a').attr('id2')+$('#num3a').attr('id2');
			 });
function nbhide(){
	nb.fadeOut();
    numm.animate({'opacity':1});
	$('#comicimg').css('opacity',1);
	$('#comic').css('background-image','url(design_img/comicbg.png)');
}
function nbshow(){
   nb.fadeIn();
   numm.animate({'opacity':0});
   $('#comicimg').css('opacity',0);
   $('#comic').css('background-image','url(design_img/comicbgblack.png)');
}
$('#nummer').click(function(){nbshow(); return false;});
$('#nummerbig').hover(function(){},function(){nbhide()});

imgswap('pointleft','pointleft.png','pointleft_ro.png');
imgswap('pointright','pointright.png','pointright_ro.png');
$('#comicshare').load('social.php?wlid='+$('#comicshare').attr('wlid'))//.css('opacity',0.3).hover(function(){$(this).animate({'opacity':1})},function(){$(this).animate({'opacity':0.3})});

if ($.browser.msie){
	$('#homecomicshare').load('social.php?wlid='+$('#homecomicshare').attr('wlid'));
}else{
	$('#homecomicshare').load('social.php?wlid='+$('#homecomicshare').attr('wlid'));//.css('opacity',0.3).hover(function(){
//		$(this).stop().animate({'opacity':1})
//	},function(){
//		$(this).stop().animate({'opacity':0.3})
//	});
}

//$('.shares').live('mouseenter',function(){
//	$(this).find('#helpWrite').show().animate({'opacity':1,'top':23});	
//});
//$('.shares').live('mouseleave',function(){
//	$(this).find('#helpWrite').animate({'opacity':0,'top':33},function(){$(this).hide()});
//});

$('#randomBalloon').css('opacity',0);
$('#nipple').hover(function(){
		$('#randomBalloon').not('.seen').addClass('seen').animate({'opacity':0},1500).show().animate({'opacity':1});
		$(this).stop().animate({'margin-top':'0px'},300,'swing').animate({'margin-top':'-5px'},100).animate({'margin-top':'0px'},100).animate({'margin-top':'-2px'},100).find('img').fadeIn();
	},function(){
		$('#randomBalloon').stop().animate({'opacity':0},function(){$(this).hide()});
		$(this).find('img').stop(true,true).fadeOut();
		$(this).stop(true,true).animate({'margin-top':'-65px'},300).animate({'margin-top':'-58px'},100).animate({'margin-top':'-63px'},100).animate({'margin-top':'-60px'},100)
		}).click(function(){
	frndcmc();
	return false;
});

//write stuff============================================================================================




var $pageNum_rs1 = 0;
var kwer = '';
var writestuffId = $('#writestuff').attr('wlid');
if (writestuffId){
	kwer = '&wlid='+writestuffId;	
}
$('#writestuff').load('writestuff.php?page='+$pageNum_rs1+kwer,function(){
	loadMessPola();	
	$(window).scroll(function(){
		loadNewMess();
	});
});




//sketches============================================================================================
if ($('#mycarousel').length>0){
	function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt)
	{
		// The index() method calculates the index from a
		// given index who is out of the actual item range.
		var idx = carousel.index(i, mycarousel_itemList.length);
		carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[idx - 1]));
	};
	 
	function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt)
	{


		carousel.remove(i);
	};
	 function mycarousel_ani(carousel, item, i, state, evt){
		 		$('#asses_over img').css({height:'245px',width:'950px'}).animate({height:'229px',width:'950px'},100).animate({height:'233px',width:'950px'},100).animate({height:'229px',width:'950px'},100);
				if (state == 'prev'){
					i_active = i_active - 1;
					$('.jcarousel-item-'+(i_active-1)+' img').css('opacity',0).load(function(){
																							 $(this).resize({'scale':0.5});$(this).css({'opacity':1})
																							 });	
					$('.jcarousel-item-'+(i_active+1)+' img').animate({'opacity':vaag,width:$('.jcarousel-item-'+(i_active+1)+' img').width()*0.5,height:$('.jcarousel-item-'+(i_active+1)+' img').height()*0.5});				
				}else{
					i_active = i_active + 1;
					$('.jcarousel-item-'+(i_active-1)+' img').animate({'opacity':vaag,width:$('.jcarousel-item-'+(i_active-1)+' img').width()*0.5,height:$('.jcarousel-item-'+(i_active-1)+' img').height()*0.5});
					$('.jcarousel-item-'+(i_active+1)+' img').css('opacity',0).load(function(){
																							 $(this).resize({'scale':0.5});$(this).css({'opacity':1})
																							 });	
				}
				$('#sketchbg img').animate({width:$('.jcarousel-item-'+(i_active)+' img').width()*2+63,height:$('.jcarousel-item-'+(i_active)+' img').height()*2+45});
				$('.jcarousel-item-'+(i_active)+' img').animate({'opacity':1,width:$('.jcarousel-item-'+(i_active)+' img').width()*2,height:$('.jcarousel-item-'+(i_active)+' img').height()*2},500,function(){});	
				$('#sketchshare').load('social.php?wlid='+$('.jcarousel-item-'+(i_active)+' img').attr('wlid'));
				$('#writestuff').attr('wlid',$('.jcarousel-item-'+(i_active)+' img').attr('wlid'));
				$('#wlid').attr('value',$('.jcarousel-item-'+(i_active)+' img').attr('wlid'));
				var $pageNum_rs1 = 0;
				var kwer = '';
				var writestuffId = $('#writestuff').attr('wlid');
				if (writestuffId){
					kwer = '&wlid='+writestuffId;	
				}
				$('#writestuff').load('writestuff.php?page='+$pageNum_rs1+kwer,function(){
					loadMessPola();	
					$(window).scroll(function(){
						loadNewMess();
					});
				});				
				
	 }
	/**
	 * Item html creation helper.
	 */
	function mycarousel_getItemHTML(item)
	{
		return '<img src="' + item.url + '" alt="' + item.title + '" wlid="' + item.wlid + '" />';
	};
	
 
	
	jQuery('#mycarousel').jcarousel({
		scroll: 1,
        size: mycarousel_itemList.length,
        itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback},
        itemVisibleOutCallback: {onBeforeAnimation: mycarousel_ani,onAfterAnimation: mycarousel_itemVisibleOutCallback},
		itemLoadCallback: setItems,
		wrap:'circular',
		animation:'normal'
	});
	
	var i_active = 2;
	var vaag = 1;

	$('.jcarousel-prev, .jcarousel-next').hover(function(){$(this).animate({'opacity':0.5})},function(){$(this).animate({'opacity':1})});
}


//polaroids============================================================================================]

//$('#snapshots').css('opacity',0);
//$('#snapshots').delay(350).animate({'opacity':1,'left':'170px'}).delay(4000).animate({'opacity':0,'left':'150px'},function(){loadforsale();});
//$('#snapshots').click(function(){loadforsale(); });

var vpage = 0;
var vrow = 0;
var vitem = 0;
function loadnew(var1,var2,var3,var4){
	//alert('?page='+var1+'&rows='+var2+'&startrow='+var3);
	$.ajax({
	  url: '/homepage.php?page='+var1+'&rows='+var2+'&startrow='+var3+'&wltypeid='+var4,
	  timeout:1000,
	  success: function(data) {
		$('#homepage').append(data);
		$('.polawait').not('.clear').addClass('clear').animate({'opacity':'1'},300).animate({'opacity':0},5000);
		$('#homepage.sell a.iconwrap').click(function(){
			loadforsale($(this).parent().attr('wlid'));
			$('#homepage.sell').animate({'top':'600px'});
			//$('#forsale').fadeIn();
			 loadfsitem($(this).parent().attr('wlid'))
			return false;
		});
	  }
	});	
}

function loadpointer(v1,page){
	if ($('#homepage').length > 0){
		if (v1 == 'init'){
				loadnew(vpage,20,vrow,page);
				vpage = vpage + 1;
				vrow = vrow + 21;
		}else{
				loadnew(vpage,7,vrow,page);
				 vpage = vpage + 1;	
				 vrow = vrow + 7;
		}
	}
}


if ($('#homepage.sell').length > 0){
	loadpointer('init','15');
}
else if ($('#homepage').length > 0){
	loadpointer('init','0');
}


//$('#morepolaroids').css({'opacity':0.5});
//$('#morepolaroids').hover(function(){$(this).animate({'opacity':1})},function(){$(this).animate({'opacity':0.5});});
$('#morepolaroids').click(function(){
	   loadpointer('','pointer');
	   $(window).scrollTop($(document).height());
	   return false;
});
//$(window).scroll(function(){
//	if  ($(window).scrollTop() == $(document).height() - $(window).height()){
//		loadpointer();
//	}
//});

//FORSALE======================================================================================
if ($('#forsalepicture').length > 0){
	$.ajax({
	  url: 'forsalepicture.php',
	  timeout:1000,
	  success: function(data) {
		  var tmp = data.split('?');
		  //$('#forsalepicture').css('background-image','url('+tmp[0]+')');
		  //$('#forsalepicture').attr('href','?wltypeid=-2&wlid='+tmp[1]);
		  $('#forsalepicture').attr('href','part2/');
	  }
   });
}

//$('#forsalepicture').css

$('#forsale').hide();
function loadforsale(var1){
	$('#snapshots').css('opacity',0);
	if (($('#forsale').attr('class') != 'loaded')){
     $('#forsale').addClass('loaded');
	 $('#forsale').fadeIn();
	loadfsitem(var1);
	}
}

function loadfsitem(var1){
 $('#fsitem').load('forsale.php?wlid='+var1+'&'+Math.floor(Math.random()*999999),function(){
	   $('#fsitem img').load(function(){
			$('#fsitem').fadeIn();
			  $('#fsshadow img').css({'height':'20px','width':$(this).width()+20});
			  $('#fsbuy').attr('href','?wltypeid=-2&wlid='+$('#fsitem img').attr('wlid'));
			  if ($('#fsitem').css('padding-left')=='1px'){
				  	$('#fsitem img').css({'left':'50%','margin-left':-$('#fsitem img').width()/2+'px'});
				  }
		  });
   });	
}

//MAILING
$('#mailing').css({'opacity':0.3});
$('#mailingBalloon').hide().css({'opacity':0});
$('#mailing').hover(function(){$(this).stop().animate({'opacity':1});$('#mailingBalloon').show().stop().animate({'opacity':1,'top':50})},function(){$(this).stop().animate({'opacity':0.3});$('#mailingBalloon').stop().animate({'opacity':0,'top':30}).hide()});
$('#mailing').bind('click',function(){
}).fancybox(settings);

$(".button").live('click',function() {
	// validate and process form here
	var emailadres = $("input#emailadres").val();
	if (emailadres == "") {
		alert('You really need to give me your e-mail address. I promise I won\'t sell it to the spam-maffia.');
	return false;
	}
	var mail = $("input#mail:checked").val();
	$.getJSON("http://dio.is-a-geek.com/johnandjohn/www/mailinglist.asp?actie=toevoegen&emailadres="+emailadres+"&mail="+mail+"&callback=?", function(data){
	});	
	  $('#mailingForm').html("<div id='message'></div>");
	  $('#message').html("<h2>I think it worked!!</h2>")
	  .append("<p>See you next Monday!</p>")
	  .hide()
	  .fadeIn(1500);
	  $.fancybox.resize();

	return false;
});


//$('#sharepage .pointer-mid').css('text-align','center');
//$('#sharepage .pointer-mid img').css('margin-left',-$('#sharepage .pointer-mid img').width()/2-40);

//SHAREPAGE (FACEBOOK ETC...)======================================================================================
$('#sharepage .pointer').css('visibility','visible').fadeIn();
var si = $('#sharepage .pointer-mid .midder img');
if ($.browser.msie){
	si.ready(function(){
		if (si.width() > 645){
			si.width(645);
			si.height(si.height()*(645/si.width()));
		}				 
	 });
}else{
	si.load(function(){
		if (si.width() > 645){
			si.width(645);
			si.height(si.height()*(645/si.width()));
		}				 
	 });	
}

$('#sharepage .pointer-bot .midder').load('social.php?wlid='+$('#sharepage .pointer-bot').attr('wlid'))//.css('opacity',0.3).hover(function(){$(this).animate({'opacity':1})},function(){$(this).animate({'opacity':0.3})});

//BUY===========================================
$('#buywrap').load('/buy.php?wlid='+$('#buywrap').attr('wlid'),function(){
		$('#city').focus(function(){
								  $(this).animate({'width':'310px'});
								  $('#marker').animate({'left':'290px'});						  
		});		
		$('#city').blur(function(){
								  $(this).animate({'width':'280px'});
								  $('#marker').animate({'left':'260px'});						  
		});				
	});

});//END


$('.selectCountry').live('click',function(){
	if($(this).index() == 0){
		$('#verzendkosten2').show();
		$('#verzendkosten').hide();	
		$('#shipping').val($('#verzendkosten2').text());
	}else{
		$('#verzendkosten').text('4');
		$('#verzendkosten').show();		
		$('#verzendkosten2').hide();	
		$('#shipping').val($('#verzendkosten').text());		
	}
});

function loadfancy(v1,v2,v3){
	v1.fancybox({
			'transitionIn'	:	'elastic',
			'transitionOut'	:	'elastic',
			'speedIn'		:	500, 
			'speedOut'		:	500, 
			'overlayShow'	:	true,
			'hideOnContentClick'	: true,
			'overlayOpacity'	: 0.85,	
			'overlayColor'	:	'#7EA43D',
			'titleShow'		:	true,
			'width'			:	'80%',
			'height'		:	'80%',	
			'titlePosition'	:	'inside',	
			'showNavArrows'	:	true,			
			'onComplete'	:	function() {
				if (v2 == 'local'){
					$('#fancybox-title').after('<div id="fancyshare"></div>');
					$('#fancyshare').load('social.php?wlid='+v3,function(){
						 addthis.init();
					});
					
				}
			}			
		})	;	
}

//sketches
function setItems(carousel, state){
	if (state == 'init'){
	$('.jcarousel-item-1 img').load(function(){$(this).css({'opacity':1,width:$('.jcarousel-item-1 img').width()*0.5,height:$('.jcarousel-item-1 img').height()*0.5});}) 
	$('.jcarousel-item-3 img').load(function(){$(this).css({'opacity':1,width:$('.jcarousel-item-3 img').width()*0.5,height:$('.jcarousel-item-3 img').height()*0.5});})
	$('.jcarousel-container').before('<div id="asses_over"><img border="0" src="../design_img/asses_over.png"></div>');
	$('.jcarousel-container').before('<div id="sketchbg"><img border="0" src="../design_img/sketchwrap.png"></div>');		
	$('.jcarousel-item-2 img').load(function(){$('#sketchbg img').animate({width:$('.jcarousel-item-2 img').width()+63,height:$('.jcarousel-item-2 img').height()+45})});
	$('#sketchshare').load('social.php?wlid='+$('.jcarousel-item-2 img').attr('wlid'));
	$('#writestuff').attr('wlid',$('.jcarousel-item-2 img').attr('wlid'));
	$('#wlid').attr('value',$('.jcarousel-item-2 img').attr('wlid'));
	var $pageNum_rs1 = 0;
	var kwer = '';
	var writestuffId = $('#writestuff').attr('wlid');
	if (writestuffId){
		kwer = '&wlid='+writestuffId;	
	}
	$('#writestuff').load('writestuff.php?page='+$pageNum_rs1+kwer,function(){
		loadMessPola();	
		$(window).scroll(function(){
			loadNewMess();
		});
	});
	}
}	

function correctShadow(){$('.messageShadow').css('bottom',-25);}

function loadMessPola(){
	$('.messPola').not('.clear').each(function(){
		if ($(this).attr('wlid').length > 0){
			$(this).load('homepage.php?wlid='+$(this).attr('wlid'),function(){
				$(this).find('.polawait').not('.clear').addClass('clear').animate({'opacity':'1'},300).animate({'opacity':0},5000);
			}).addClass('clear');
		}else{
			$(this).closest('.messageWrap').removeClass('op');
		}
		setTimeout('correctShadow()',400);
	});	
}
var $pageNum_rs1 = 0;
var kwer = '';
var writestuffId = $('#writestuff').attr('wlid');
if (writestuffId){
	kwer = '&wlid='+writestuffId;	
}
function loadNewMess(){
	if  ($(window).scrollTop() == $(document).height() - $(window).height()){
		$pageNum_rs1 ++;				
		$.get('writestuff.php?page='+$pageNum_rs1+kwer,function(data){
			$('#writestuff').append(data);
				loadMessPola();			
		});
	}	
}

(function($){

  var url1 = /(^|&lt;|\s)(www\..+?\..+?)(\s|&gt;|$)/g,
      url2 = /(^|&lt;|\s)(((https?|ftp):\/\/|mailto:).+?)(\s|&gt;|$)/g,

      linkifyThis = function () {
        var childNodes = this.childNodes,
            i = childNodes.length;
        while(i--)
        {
          var n = childNodes[i];
          if (n.nodeType == 3) {
            var html = $.trim(n.nodeValue);
            if (html)
            {
              html = html.replace(/&/g, '&amp;')
                         .replace(/</g, '&lt;')
                         .replace(/>/g, '&gt;')
                         .replace(url1, '$1<a href="http://$2">$2</a>$3')
                         .replace(url2, '$1<a href="$2">$2</a>$5');
              $(n).after(html).remove();
            }
          }
          else if (n.nodeType == 1  &&  !/^(a|button|textarea)$/i.test(n.tagName)) {
            linkifyThis.call(n);
          }
        }
      };

  $.fn.linkify = function () {
    return this.each(linkifyThis);
  };

})(jQuery);

