$(document).ready( function() {
	initPreview();
	$("#navi a:not([class*='active'])")
		.css( { backgroundPosition: "0px 0px" } )
		.hover(
			function() {
				$(this).stop().animate(
					{ backgroundPosition: "(0px -164px)" },
					{ duration: 400 }
				)
			},
			function() {
				$(this).stop().animate(
					{ backgroundPosition:"(0px 0px)"},
					{duration: 500, complete: function() {
						$(this).css( {backgroundPosition: "0px 0px"} );
					}}
				)
			}
		);
	$("ul.foldable li span.btn").click(
		function() {
			if( $(this).parents('li').hasClass('active') ) {
				$(this).parents('ul').children('li').removeClass('active');
				$(this).parents('li').removeClass('active');
			} else {
				$(this).parents('ul').children('li').removeClass('active');
				$(this).parents('li').addClass('active');
			}
		}
	);
	$('.show-friends').toggle(
		function() {
			$('ul.list li').css( { display: 'none' } );
			$('.friend').parents('li').css( { display: 'block' } );
			$(this).attr('value','show all');
		},
		function() {
			$('ul.list li').css( { display: 'block' } );
			$(this).attr('value','show friends');
		}
	);
	initForms();
	initIMlinks();
	setTimeout("checkIm()", 5000 );
	imIntval = setInterval( "checkIm()", 15000 );
	$('#warnink .dismiss').click( function() {
		createCookie('warnink','read',360);
		$('#warnink').slideUp(550,function() {
			$(this).remove();
		});
	});
	$('#refresh-online').click( function() {
		$(this).parent( 'h3' ).addClass('loading');
		$('ul#onlinelist').load( '/includes/index-online.php', function() {
			$(this).prev('h3').removeClass('loading');
		});
	} );
	function findValueCallback(event, data, formatted) {
		$("<li>").html( !data ? "No match!" : "Selected: " + formatted).appendTo("#result");
	}
	if( $("#tagField").get(0) ) {
		$.get( "/tagsuggestions.php", function( data ) {
			eval( data );
			$("#tagField").autocomplete(taglist, {
				multiple: true,
				max: 8,
				mustMatch: false,
				autoFill: false
			});
		});
	}
	if( $("#stags").get(0) ) {
		$.get( "/tagsuggestions.php", function( data ) {
			eval( data );
			$("#stags").autocomplete(taglist, {
				multiple: true,
				max: 8,
				mustMatch: false,
				autoFill: false
			});
		});
	}
	
	if( $("input#s").get(0) ) {
		$("input#s").autocomplete("/search-autocomplete.php", {
			width: 260,
			selectFirst: false,
			max: 8
		});
		$("input#s").result(function(event, data, formatted) {
			if (data) {
				location.href = '/member/'+data[1]+'/';
			}
		});
	}
	
	$('#tagForm').submit( function() {
		var tags = $('#tagField').val();
		var str = $(this).serialize();
		if( tags != "" ) {
			$('#tagField').attr( 'disabled', 'disabled' );
			$('#taglist').load('/picture.php?'+str, function() {
				$('#tagField').val('');
				$('#tagField').attr( 'disabled', '' );
			});
		}
		return false;
	});
	$('.delete').bind('click', function(event) {
		if( confirm( "Are you sure?" ) ) {
			return true;
		}
		return false;
	});
	$('.delete').css( {display: 'inline'} );
	setTimeout( "eval($('#kruunu').fadeIn('slow'))", 1000 );
	if( $("#notifications").get(0) ) {
		checkNotifications();
		notificationsInterval = setInterval( "checkNotifications()", 30000 );
	}
	
	initKeyNavigation();
	
	$('#mark-favorite').bind('click', function() {
		$.get( $(this).attr('href'), function(data) { 
			if( data == 'true' ) {
				$('#mark-favorite').text('Remove from favorites');
				$('#mark-favorite').addClass('isfav');
			} else {
				$('#mark-favorite').text('Add to favorites');
				$('#mark-favorite').removeClass('isfav');
			}
		} );
		$(this).blur();
		return false;
	});
	
	$("ul.thumb-list li a").each( function() {
		$(this).parents('li').append( '<a href="'+$(this).attr('href')+'" class="thumb-info">' + $(this).attr('title') + '</a>' );
		$(this).removeAttr('title');
		$(this).parents('li').hover(
			function() {
				$(this).children('a.thumb-info').show();
			},
			function() {
				$(this).children('a.thumb-info').hide();
			}
		);
	});

}); // END INIT


var notificationsOpen = false;
function checkNotifications() {
	var now = new Date();
	var ms = now.getTime();
	if( !notificationsOpen && !readCookie('notifications') ) {
		$.get('/notifications.php?'+ms, function(data) {
			if( data != '0' ) {
				var now = new Date();
				var ms = now.getTime();
				$.get('/notifications.php?show=true&'+ms, function( data ) {
					notificationsOpen = true;
					$("#wrapper").after('<div id="notifications-temp"></div>');
					$("#notifications-temp").html( data );
					$("#notifications-temp .dismiss").bind( 'click', function() {
						$("#notifications-temp").fadeOut();
						createCookie('notifications','hide',false,5)
						return false; 
					});
					$("#notifications").fadeOut('fast', function() {
						$("#notifications-temp").slideDown('slow');
					});
				});
			} else {
				$("#notifications").fadeOut();
			}
		});
	}
}
defaultStatus = '';

var inputFocus = false;
function initKeyNavigation() {
	$('input, textarea').bind( 'focus', function() { inputFocus = true; } );
	$('input, textarea').bind( 'blur', function() { inputFocus = false; } );
	if($('a.image-next').get(0) || $('a.image-previous').get(0)) {
		$(window).keyup(function(event) {
			if(event.keyCode == 37 && !event.altKey && $('a.image-previous').get(0) && !inputFocus) {
				location.href = $('a.image-previous').attr('href');
			}
			if(event.keyCode == 39 && !event.altKey && $('a.image-next').get(0) && !inputFocus) {
				location.href = $('a.image-next').attr('href');
			}
		});
	}
}


var scrollTimer = 0;
function scrollToTop() {
	clearTimeout( scrollTimer );
	if( document.documentElement.scrollTop > 0 ) {
		amount = Math.floor(document.documentElement.scrollTop / 10);
		if( amount < 1 ) amount = 1;
		window.scrollBy( 0, -amount );
		scrollTimer = setTimeout( "scrollToTop()", 10 );
	} else {
		window.scrollTo( 0, 0 );
	}
}


function initForms() {
	$('form#membersform select').change( function() {
		var sort = ( $('#membersform #o').val()); 
		if(sort == 'geografic') {
			var country = $('#membersform #c').val();
			location.href = '/members/geografic/' + country + '/';
		} else if( sort == 'newest' ) {
			var year = $('#membersform #year').val();
			location.href = '/members/newest/' + year + '/';
		}
	});
	$('form#picturesform select').change( function() {
		var cat = $('#picturesform #cat').val();
		if( cat == 0 )
			location.href = '/pictures/';
		else
			location.href = '/pictures/' + cat + '/';
	});
}

defaultStatus = '';

/* INSTANT MESSAGES */

function checkIm() {
	var now = new Date();
	var ms = now.getTime();
	$.get('/im_check.php?'+ms, function(data) {
		if( data == "x" ) {
			clearInterval(imIntval);
		} else if( data != 'f' ) {
			$('#messages a.instant-messages').addClass('newmessages');
			$('#messages a.instant-messages').text('Instant messages (' + data + ')');
			window.status = "You have new messages";
		} else {
			$('#messages a.instant-messages').removeClass('newmessages');
			$('#messages a.instant-messages').text('Instant messages');
			window.status = "";
		}
	});
}



var imPage = 1;
function initIMlinks() {
	$('a.im').bind( 'click', function(event) {
		var user_id = $(this).attr('href').replace( "#", "" );
		//winWidth = $(window).width();
		//leftPos = winWidth / 2 - 500 / 2;
		//openIMsendmessage( event, user_id, leftPos, event.pageY );
		//activateIMwindow( $('#ims-'+user_id) );
		openCompose( user_id );
		return false;
	});
	$('a.instant-messages').bind( 'click', function(event) {
		$(this).removeClass('newmessages');
		imPage = 1;
		//openIMmessages(event);
		openMessages();
		return false;
	});
}

function activateIMwindow( el ) {
	$('.im-window').removeClass( 'activeWindow' );
	$(el).addClass( 'activeWindow' );
}

function openMessages() {
	var imwindow = window.open('/instantmessages.php', 'im', 'toolbar=no,menu=no,status=no,scrollbars=no,width=500,height=600');
}

function openCompose( uid ) {
	var imwindow = window.open('/instantmessages_compose.php#u' + uid, 'im', 'toolbar=no,menu=no,status=no,scrollbars=no,width=500,height=600');
}

function openIMmessages(event) {
	if( !$('#instant-messages').get(0) ) {
		winScrollY = $(window).scrollTop();
		winWidth = $(window).width();
		winHeight = $(window).height();
		topPos = winHeight / 2 - 400 / 2 + winScrollY;
		leftPos = winWidth / 2 - 300 / 2;
		$('body')
			.append('<div id="instant-messages" class="im-window im-messages"></div>');
			$('#instant-messages').css({ top:topPos, left:leftPos });
		imPage = 1;
	} else {
		$('#instant-messages').empty();
	}
		$('#instant-messages')
			.bind( 'click', function() {
				closeIMwindow($(this));
				imPage = 1;
			})
			/* .css({ top:topPos, left:leftPos })*/
			.load( '/im_messages.php', { page: imPage }, function() {
				$(this).unbind('click');
				$(this).children('.im-top').children('.im-close').bind( 'click', function( event ) {
					closeIMwindow($(event.target).parents('div.im-window'));
					return false;
				});
				$(this).children('.im-top').bind('drag', function( event ){
					var leftp = event.offsetX-5;
					if( leftp < 0 ) leftp = 0;
					elw = $(this).parent('div.im-window').width() + 10;
					if( leftp > $(window).width() - elw )
						leftp = $(window).width() -elw;
					var topp = event.offsetY-5;
					if( topp < 0 ) topp = 0;
					$(this).parent('div.im-window').css({ top:topp, left:leftp });
					activateIMwindow( $(this).parent('div.im-window') );
				});
				$(this).find('.next').bind('click', function( event ) {
					imPage++;
					openIMmessages();
					return false;
				});
				$(this).find('.prev').bind('click', function( event ) {
					imPage--;
					if( imPage > 0 ) {
						openIMmessages();
					} else {
						imPage = 1;
					}
					return false;
				});
				$(this).children('.im-top').bind('dragstart', function( event ){
					//$(this).parent('div.im-window').addClass('dragged');
				});
				$(this).children('.im-top').bind('dragend', function( event ){
					$(this).parent('div.im-window').removeClass('dragged');
				});
				$(this).children('.im-top').bind('mousedown', function( event ){
					activateIMwindow($(this).parent('div.im-window'));
				});
				$(this).unbind('click');
				$(this).find('li').bind('click', function( event ) {
					var message_id = $(this).attr('id').replace('m', '');
					openIMmessage( event,message_id );
					$(this).addClass('openIM');
				});
				$(this).find('.del').bind('click', function( event ) {
					$(this).parent('li').unbind('click');
					var message_id = $(this).parent('li').attr('id').replace('m', '');
					deleteIM( message_id );
				});
			})
	//}
	activateIMwindow( $('#instant-messages') );
}

function openIMsendmessage( event, id, xPos, yPos ) {
	winScrollY = $(window).scrollTop();
	winHeight = $(window).height();
	topPos = event.pageY + 20;
	topPos = winHeight / 2 - 300 / 2 + winScrollY;
	if( !$('#ims-'+id).get(0) ) {
		$('body')
			.append('<div id="ims-'+id+'" class="im-window"></div>');
		$('#ims-'+id)
			.bind('mousedown', function( event ) {
				activateIMwindow( $(this ) );
			})
			.css({ top:topPos, left:xPos })
			.load( '/im_send.php', { user_id: id }, function() {
				$(this).children('.im-top').children('.im-close').bind( 'click', function( event ) {
					closeIMwindow($(event.target).parents('div.im-window'));
					return false;
				});
				$(this).children('.im-top').bind('drag', function( event ){
					var leftp = event.offsetX-5;
					if( leftp < 0 ) leftp = 0;
					elw = $(this).parent('div.im-window').width() + 10;
					if( leftp > $(window).width() - elw )
						leftp = $(window).width() -elw;
					var topp = event.offsetY-5;
					if( topp < 0 ) topp = 0;
					$(this).parent('div.im-window').css({ top:topp, left:leftp });
					activateIMwindow( $(this).parent('div.im-window') );
				});
				$(this).children('.im-top').bind('dragstart', function( event ){
					//$(this).parent('div.im-window').addClass('dragged');
				});
				$(this).children('.im-top').bind('dragend', function( event ){
					$(this).parent('div.im-window').removeClass('dragged');
				});
				$(this).children('.im-top').bind('mousedown', function( event ){
					activateIMwindow($(this).parent('div.im-window'));
				});
				$(this).find('form').bind('submit', function( event ) {
					var ser = $(this).serialize();
					if( $(this).find('textarea').val() != '' ) {
						$(this).find('input[type=submit]')
							.attr('disabled', 'disabled')
							.addClass( 'disabled' );
						$(this).parents('div.im-content').load(
							'/im_send.php?'+ser,
							function(data) {
								closeIMwindow($(this).parents('div.im-window'));
							}
						);
					}
					return false;
				});
			});
	}
}




function openIMmessage( event, id ) {
	winScrollY = $(window).scrollTop();
	winHeight = $(window).height();
	topPos = event.pageY + 20;
	topPos = parseInt(winHeight / 2 - 300 / 2 + winScrollY);
	leftPos = event.pageX+5;
	if( leftPos + 460 > $(window).width() ) leftPos = $(window).width() - 460;
	if( !$('#message-'+id).get(0) ) {
		$('body')
			.append('<div id="message-'+id+'" class="im-window"></div>');
		$('#message-'+id)
			.css({ top:topPos, left:leftPos })
			.bind('mousedown', function( event ) {
				activateIMwindow( $(this ) );
			}) // end bind
			.load( '/im_messages.php', { message_id: id }, function() {
				$('#m'+id+ ' .new').remove();
				activateIMwindow( $(this ) );
				$(this).children('.im-top').children('.im-close').bind( 'click', function( event ) {
					closeIMwindow($(event.target).parents('div.im-window'));
					return false;
				});
				$(this).children('.im-top').bind('drag', function( event ){
					var leftp = event.offsetX-5;
					if( leftp < 0 ) leftp = 0;
					elw = $(this).parent('div.im-window').width() + 10;
					if( leftp > $(window).width() - elw )
						leftp = $(window).width() -elw;
					var topp = event.offsetY-5;
					if( topp < 0 ) topp = 0;
					$(this).parent('div.im-window').css({ top:topp, left:leftp });
					activateIMwindow( $(this).parent('div.im-window') );
				});
				$(this).children('.im-top').bind('dragstart', function( event ){
					//$(this).parent('div.im-window').addClass('dragged');
				});
				$(this).children('.im-top').bind('dragend', function( event ){
					$(this).parent('div.im-window').removeClass('dragged');
				});
				$(this).children('.im-top').bind('mousedown', function( event ){
					activateIMwindow($(this).parent('div.im-window'));
				});
				$(this).find('form').bind('submit', function( event ) {
					var ser = $(this).serialize();
					if( $(this).find('textarea').val() != '' ) {
						$(this).find('input[type=submit]')
							.attr('disabled', 'disabled')
							.addClass( 'disabled' );
						$(this).parents('div.im-content').load(
							'/im_send.php?'+ser,
							function(data) {
								closeIMwindow($(this).parents('div.im-window'));
							}
						);
					}
					return false;
				});
			}) // end load
			
			
	}
}

function deleteIM( id ) {
	closeIMwindow( $("#message-" + id ) );
	$.get('/im_messages.php', {del_id: id}, function(data) {
		$("#m"+id).fadeOut('fast');
	});
}

function closeIMwindow( el ) {
	if( $(el).attr('id') ) {
		var closingWindow = $(el).attr('id').replace( /[A-z-]+/, '' );
		if( closingWindow != '' ) {
			$("#m"+closingWindow).removeClass('openIM');
		}
	}
	$(el).fadeOut( 200, function() {
		$(this).remove();
	});
}


/* HÄLÄRIT */

function openAlert( message ) {
	$('body').append('<div id="curtain"></div>');
	var arrPageSize = ___getPageSize();
	var arrScroll = ___getPageScroll();
	var leftPos = arrPageSize[0] / 2 - 320 / 2;
	
	$('body').append('<div id="alert"><div id="alert-text"></div><input type="button" value="close" class="btn" /></div>');
	$('#alert').css({display: 'none', width: '300px',height: '200px',padding: '10px', position: 'absolute', left: leftPos, top: '200px',background: '#eee', zIndex: 3});
	$('#alert #alert-text').html( message );
	
	$('#curtain').css({position:'absolute',left:0,top:0,width:arrPageSize[0],height:arrPageSize[1],background: '#000', color: '#fff',opacity: .001, zIndex: 2});
	$('#curtain').animate({opacity: .75}, 'fast', function() {
		$('#alert').css({display: 'block'});
	});
	$('#alert .btn').bind( 'click', function() {
		$('#alert').remove();
		$('#curtain').fadeOut('fast', function() { $(this).remove() } );
	});
}

/* KEKSEI */

function createCookie(name,value,days,minutes) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	} else if( minutes ) {
		var date = new Date();
		date.setTime(date.getTime()+(minutes*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(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 eraseCookie(name) {
	createCookie(name,"",-1);
}


/* COMMON STUFF */

function urlencode(str) { str = escape(str); str = str.replace('+', '%2B'); str = str.replace('%20', '+'); str = str.replace('*', '%2A'); str = str.replace('/', '%2F'); str = str.replace('@','%40'); return str; }
function trim(str, chars) { return ltrim(rtrim(str, chars), chars); }
function ltrim(str, chars) { chars = chars || "\\s"; return str.replace(new RegExp("^[" + chars + "]+", "g"), ""); }
function rtrim(str, chars) { chars = chars || "\\s"; return str.replace(new RegExp("[" + chars + "]+$", "g"), ""); }
function isNull(val){return(val==null);}
Array.prototype.inArray = function( search_phrase ) { for( var i = 0; i < this.length; i++ ) { if( search_phrase == this[i] ) { return true; } } return false; }


function ___getPageSize(){var xScroll,yScroll;if(window.innerHeight&&window.scrollMaxY){xScroll=window.innerWidth+window.scrollMaxX;yScroll=window.innerHeight+window.scrollMaxY;}else if(document.body.scrollHeight>document.body.offsetHeight){xScroll=document.body.scrollWidth;yScroll=document.body.scrollHeight;}else{xScroll=document.body.offsetWidth;yScroll=document.body.offsetHeight;}
var windowWidth,windowHeight;if(self.innerHeight){if(document.documentElement.clientWidth){windowWidth=document.documentElement.clientWidth;}else{windowWidth=self.innerWidth;}
windowHeight=self.innerHeight;}else if(document.documentElement&&document.documentElement.clientHeight){windowWidth=document.documentElement.clientWidth;windowHeight=document.documentElement.clientHeight;}else if(document.body){windowWidth=document.body.clientWidth;windowHeight=document.body.clientHeight;}
if(yScroll<windowHeight){pageHeight=windowHeight;}else{pageHeight=yScroll;}
if(xScroll<windowWidth){pageWidth=xScroll;}else{pageWidth=windowWidth;}
arrayPageSize=new Array(pageWidth,pageHeight,windowWidth,windowHeight);return arrayPageSize;}
	function ___getPageScroll(){var xScroll,yScroll;if(self.pageYOffset){yScroll=self.pageYOffset;xScroll=self.pageXOffset;}else if(document.documentElement&&document.documentElement.scrollTop){yScroll=document.documentElement.scrollTop;xScroll=document.documentElement.scrollLeft;}else if(document.body){yScroll=document.body.scrollTop;xScroll=document.body.scrollLeft;}
arrayPageScroll=new Array(xScroll,yScroll);return arrayPageScroll;}



/* POSITIONS & OTHER GEOMETRY */
function mouseX(e) {
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	var arr = new Array( posx, posy );
	return arr;
}

function getElementPosition(elem) {
    var offsetTrail = elem;
    var offsetLeft = 0;
    var offsetTop = 0;
    while (offsetTrail) {
        offsetLeft += offsetTrail.offsetLeft;
        offsetTop += offsetTrail.offsetTop;
        offsetTrail = offsetTrail.offsetParent;
    }
	offsetWidth = elem.offsetWidth;
    if (navigator.userAgent.indexOf("Mac") != -1 && 
        typeof document.body.leftMargin != "undefined") {
        offsetLeft += document.body.leftMargin;
        offsetTop += document.body.topMargin;
    }
    return {left:offsetLeft, top:offsetTop, width:offsetWidth};
}


function initPreview() {
	var previewbox = document.createElement('div');
	previewbox.setAttribute('id', 'previewBox');
	previewbox.className = 'tooltip';
	document.body.appendChild( previewbox );
	var links = document.getElementsByTagName( 'a' );
	if( document.getElementById( 'previewBox' ) ) {
		for( var i = 0; i < links.length; i++ ) {
			if( links[ i ].className.indexOf( 'showpreview' ) > -1 ) {
				var lnk = links[ i ];
				var tmp = lnk.href.split( '/' );
				var name_fixed = tmp[ 4 ];
				lnk.name_fixed = name_fixed;
				links[ i ].onmouseover = function(event) {
					showPreview( event, this );
				}
				links[ i ].onmouseout = function(event) {
					hidePreview();
				}
				links[ i ].onmousemove = function(event) {
					repositionPreview(event, this);
				}
			}
		}
	}
}

var previewName = '';
var previewArray = new Array();
function showPreview( e, lnk ) {
	previewName = lnk.name_fixed;
	document.getElementById( 'previewBox' ).style.display = 'none';
	if( previewArray[ lnk.name_fixed ] ) {
		mouseP = mouseX(e);
		document.getElementById( 'previewBox' ).style.left = mouseP[0] + 20 + 'px';
		document.getElementById( 'previewBox' ).style.top = mouseP[1] + 20 + 'px';
		document.getElementById( 'previewBox' ).innerHTML = previewArray[ lnk.name_fixed ];
		document.getElementById( 'previewBox' ).style.display = 'block';
		return;
	}
	var httprequest = false;
	if (window.XMLHttpRequest) {
		httprequest = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		httprequest = new ActiveXObject("Microsoft.XMLHTTP");
	}
	var requestPage = '/preview.php?name_fixed=' + lnk.name_fixed;
	httprequest.open( "GET", requestPage, true );
	httprequest.onreadystatechange = function() {
		if( httprequest.readyState == 4 && httprequest.status == 200 ) {
			previewArray[ lnk.name_fixed ] = httprequest.responseText;
			if( previewName == lnk.name_fixed ) {
				mouseP = mouseX(e);
				document.getElementById( 'previewBox' ).style.display = 'none';
				document.getElementById( 'previewBox' ).style.top = mouseP[1] + 20 + 'px';
				document.getElementById( 'previewBox' ).style.left = '-300px';
				document.getElementById( 'previewBox' ).innerHTML = httprequest.responseText;
				document.getElementById( 'previewBox' ).style.display = 'block';
				setTimeout("eval(\"document.getElementById( 'previewBox' ).style.left = "+mouseP[0]+" + 10 + 'px'\")",10);
			}
		}
	}
	httprequest.send( null );
}

function repositionPreview(e, lnk) {
	mouseP = mouseX(e);
	document.getElementById( 'previewBox' ).style.top = mouseP[1] + 20 + 'px';
	document.getElementById( 'previewBox' ).style.left = mouseP[0] + 10 + 'px';
}

function hidePreview() {
	previewName = '';
	document.getElementById( 'previewBox' ).style.display = 'none';
}

/* FIX FOR OPERA */
var height_ = jQuery.fn.height;
jQuery.fn.height = function() {
    if ( this[0] == window && jQuery.browser.opera && jQuery.browser.version >= 9.50)
        return window.innerHeight;
    else return height_.apply($(this[0]));
};
