var chatapp;
var timer_clock;

function Over(obj){obj.style.backgroundColor="d5e65b";}
function Out(obj){obj.style.backgroundColor="";}
function overMenu(obj, num){obj.src='images/button_'+num+'_over.jpg';}
function outMenu(obj, num){obj.src='images/button_'+num+'.jpg';}
/* function $(id){return document.all ? document.all[id] : document.getElementById ? document.getElementById(id) : null;} */

function Clock(){
	if(times){
		times[2]=times[2];
		times[1]=times[1];
		times[0]=times[0];
		
		times[2]++;
		if (times[2]>=60){
			times[2]=0;
			times[1]++;
			if(times[1]>=60){
				times[1]=0;
				times[0]++;
				if(times[0]>=24){
					times[0]=0;
				}
			}
		}
		var tmp_times = times;
		for (i=0;i<tmp_times.length;i++){
			tmp_times[i] = tmp_times[i].toString();
			if (tmp_times[i].length==1){
				tmp_times[i] = "0"+tmp_times[i];
			}
		}
		document.getElementById('times').innerHTML=""+tmp_times[0]+":"+tmp_times[1]+":"+tmp_times[2]+"";
		var timer_clock = setTimeout("Clock()", 1000);
	}
}

function playSound(srcs){
	var srcs='http://www.horse-nation.nl/sounds/'+srcs;	
	document.getElementById("sound").innerHTML += '<EMBED id="shooter" SRC="'+srcs+'" HIDDEN="true" loop="false"  AUTOSTART="true" />'; 
}

function GetMoney(num)
{
	var num = Math.floor(Math.floor(num*100+0.50000000001)/100).toString();
	for (var i=0;i<Math.floor((num.length-(1+i))/3);i++)
	{
		num=num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));
	}
	return num;
}

function GetChatApp()
{
	if (!chatapp)
	{
		var chatapp=window.open("pages/chatbox.php", "ChatBox", "toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=600,height=450");
	}
	else
	{
		window.chatapp.focus();	
	}
}

function Resize(max_length){
	for(i=14;i<document.images.length;i++){
		if(document.images[i].src.match("horse-nation.nl") != 'horse-nation.nl'){
			if(parseInt(document.images[i].width) > max_length){		
				var widths = ResizeImage(new Array(document.images[i].width,document.images[i].height), max_length);	
				document.images[i].width = widths[0];
				document.images[i].height = widths[1];
			}
		}
	}
}

function ResizeImage(widths, max_length){
	if (widths[0]<widths[1]){
	    var iiihh=1;
	    var pc_sz1=widths[1];
	    var pc_sz2=widths[0]; 
	}
	else{
	    var iiihh=0;
	    var pc_sz1=widths[0];
	    var pc_sz2=widths[1]; 
	}
	if (pc_sz1>max_length){
	    var pc_sz_tmp=Math.round(max_length/(pc_sz1/100));
	    widths[0]=Math.round((pc_sz1/100)*pc_sz_tmp);
	    widths[1]=Math.round((pc_sz2/100)*pc_sz_tmp);
	}
	else{
	    widths[0]=pc_sz1;
	    widths[1]=pc_sz2;
	}
	var size= new Array(0,0);
	if (iiihh==1){
	    size[0]=widths[1];
	    size[1]=widths[0];
	}
	else{
	    size[0]=widths[0];
	    size[1]=widths[1];
	}	
	return size;
}


var id = 111;

$(document).ready(function() {


	$(".info").each(function(i){
		
		$("body").append("<div class=\"hovertip\" id=\"hovertip"+i+"\"><p>"+$(this).attr('rel')+"</p></div>");
		var my_hovertip = $("#hovertip"+i);
		
		$(this).removeAttr('rel');
		$(this).mouseover(function(){	
			my_hovertip.fadeIn(400);
		});
		
		$(this).mousemove(function(e){
			my_hovertip.css({left:e.pageX+5, top:e.pageY+5});
		});
		
		$(this).mouseout(function(){
			my_hovertip.fadeOut(400);
		});
		
	});
	
	$('.message_block').each(function(i){
		
		if (id == 1){
			$(this).attr('id', 'message_block_'+i);
			rel = $(this).attr('rel');
			
			$(this).html('<div id="message_block_'+i+'_orig">'+$(this).html()+'</div><div id="message_block_'+i+'_divs" style="display:none;"><div style="float:left;width:90%;margin:0px;padding:0px">'+$(this).html()+'</div><div style="float:right;width:10%;margin:0px;padding:0px;position:relative;"><input style="border:1px solid #e8f0ba;background:#d5e65b;color:#000;font-size:10px;height:15px" id="report_'+i+'" type="button" class="btn" value="Rapporteer misbruik" /></div></div>');
			$(this).parent().parent().parent().parent().wrap('<div id="message_block_'+i+'_wrapper" />');
			
			$('#message_block_'+i+'_wrapper').bind("mouseover", function(){
				$('#message_block_'+i+'_orig').hide();
				$('#message_block_'+i+'_divs').show();
			});			
			$('#message_block_'+i+'_wrapper').bind("mouseout", function(){
				$('#message_block_'+i+'_orig').show();
				$('#message_block_'+i+'_divs').hide();
			});
			
			$('#report_'+i).bind('click', function(){
			
				rel = $('#message_block_'+i).attr('rel');	
				location.href = "?item=report&t=m&i="+rel;
			});
		}	
	});
	
	$('.guest_block').each(function(i){
		if (id == 1){
			
			$(this).attr('id', 'guest_block_'+i);
			rel = $(this).attr('rel');
			
			$(this).html('<div id="guest_block_'+i+'_orig">'+$(this).html()+'</div><div id="guest_block_'+i+'_divs" style="display:none;"><div style="float:left;margin:0px;padding:0px">'+$(this).html()+'</div><div style="float:right;margin:0px;padding:0px;position:relative;"><input style="border:1px solid #e8f0ba;background:#d5e65b;color:#000;font-size:10px;height:15px" id="report_'+i+'" type="button" class="btn" value="Rapporteer misbruik" /></div></div>');
					
			$(this).parent().bind("mouseover", function(){
				$('#guest_block_'+i+'_orig').hide();
				$('#guest_block_'+i+'_divs').show();
			});			
			$(this).parent().bind("mouseout", function(){
				$('#guest_block_'+i+'_orig').show();
				$('#guest_block_'+i+'_divs').hide();
			});
			
			$('#report_'+i).bind('click', function(){
				rel = $('#guest_block_'+i).attr('rel');	

				location.href = "?item=report&t=g&i="+rel;
			});
		}
	});
	
	
	
/*
	$('.post_block').each(function(i){
		if (id == 1){
			
			$(this).attr('id', 'post_block_'+i);
			rel = $(this).attr('rel');
			
			$(this).html('<div id="post_block_'+i+'_orig">'+$(this).html()+'</div><div id="post_block_'+i+'_divs" style="display:none;"><div style="float:left;margin:0px;padding:0px">'+$(this).html()+'</div><div style="float:right;margin:0px;padding:0px;position:relative;"><input style="border:1px solid #e8f0ba;background:#d5e65b;color:#000;font-size:10px;height:15px" id="report_'+i+'" type="button" class="btn" value="Rapporteer misbruik" /></div></div>');
					
			$(this).parent().bind("mouseover", function(){
				$('#post_block_'+i+'_orig').hide();
				$('#post_block_'+i+'_divs').show();
			});			
			$(this).parent().bind("mouseout", function(){
				$('#post_block_'+i+'_orig').show();
				$('#post_block_'+i+'_divs').hide();
			});
			
			$('#report_'+i).bind('click', function(){
				rel = $('#post_block_'+i).attr('rel');	

				location.href = "?item=report&t=f&i="+rel;
			});
		}
	});
*/

	
	
	
	$("a.fancy").fancybox({
		'transitionIn' : 'none',
		'transitionOut' : 'none',
		'titlePosition' : 'over',
		'titleFormat' : function(title, currentArray, currentIndex, currentOpts) {
		return '<span id="fancybox-title-over">Screenshot ' + (currentIndex + 1) + ' van ' + currentArray.length + ' ' + title + '</span>';
		}
	}); 
	
	
	
	

	$("input[rel=moneysend]").bind('keyup click change', function(){
		money = $(this).val();
		amount = 0;
		if (money != ''){
			if (money >= 10 && money <= 1000000){
				money = Math.round((money / 100) * 95);		
			}
			else{
				money = '-';
			}
		}
		else{
			money = '-';
		}
		$('#moneyrecieve').html(money);

		
		
	});
	
	

	
	if (document.getElementsByClassName){
		if (document.getElementsByClassName('ubbimg')){
			var imgs=document.getElementsByClassName('ubbimg');
			for(i in imgs){
				var img = new Image();
				img.src = imgs[i].src;	
			}
		}
	}

	function size() {
  var myWidth = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    myWidth = window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    myWidth = document.body.clientWidth;
  }
	return myWidth;
}

function height() {
  var myWidth = 0;
  if( typeof( window.innerHeight ) == 'number' ) {
    myWidth = window.innerHeight;
  } else if( document.documentElement &&  document.documentElement.clientHeight ) {
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && document.body.clientHeight ) {
    myWidth = document.body.clientHeight;
  }
	return myWidth;
}


var size = size();
var sizeh = height();

	
	if (document.getElementsByClassName == undefined) {
		document.getElementsByClassName = function(className)
		{
			var hasClassName = new RegExp("(?:^|\\s)" + className + "(?:$|\\s)");
			var allElements = document.getElementsByTagName("*");
			var results = [];
	
			var element;
			for (var i = 0; (element = allElements[i]) != null; i++) {
				var elementClass = element.className;
				if (elementClass && elementClass.indexOf(className) != -1 && hasClassName.test(elementClass))
					results.push(element);
			}
	
			return results;
		}
	}

function writeCookie()
{
var today = new Date();
var the_date = new Date("December 31, 2023");
var the_cookie_date = the_date.toGMTString();
var the_cookie = "width="+ size;
var the_cookie = the_cookie + ";expires=" + the_cookie_date;
document.cookie=the_cookie;
var the_date = new Date("December 31, 2023");
var the_cookie_date = the_date.toGMTString();
var the_cookie = "height="+ sizeh;
var the_cookie = the_cookie + ";expires=" + the_cookie_date;
document.cookie=the_cookie;
}
writeCookie();

function resizethem(){
	if (imgs){
		for(i in imgs){
			var img = new Image();
			img.src = imgs[i].src;	
			
			var width = parseInt(imgs[i].width);
			var height = parseInt(imgs[i].height);
			if (width > size - 350){
				var orig = width / 100;
				var precent = Math.floor((size - 350) / orig);
				var n_height = Math.floor((height / 100) * precent);
				
				imgs[i].width = size - 350;
				imgs[i].height = n_height;
		
			}
		}
	}
}
resizethem();

setTimeout("resizethem();", 5000);

	
	
});


