	// Imgland.net - Author: Alexander Løvheim (Dreamsoft.no)
	// Makes toggle on/off
	function toggle(id,byid) {
		var div = document.getElementById(id);
		var byi	= document.getElementById(byid);
		if(div.style.display == 'none') {
			div.style.opacity		= '0';
			div.style.filter		= 'alpha(opacity=0)';
			div.style.display 		= 'block';
			byi.style.background	= '#EAEAEA';
			dsDyn.fade(id, 'in', 10, 10);
			if(id == 'chat_box') {
				initChat(1000);
				}
		} else {
			dsDyn.fade(id, 'out', 10, 10);
			setTimeout(function() { div.style.display = 'none'; }, 100);
			byi.style.background	= '#FFF';
			// Hotfix for chatbox
			if(id == 'chat_box') {
				closeChat();
				}
		}
	}
	
	function toggleover(id) {
		var div = document.getElementById(id);
		if(div.style.background == '#EAEAEA')
			div.style.background = '#FFF';
		else
			div.style.background = '#EAEAEA';
	}

	function toggleout(id,byi) {
		var div = document.getElementById(id);
		var byi = document.getElementById(byi);
		if(byi.style.display == 'block')
			div.style.background = '#EAEAEA';
		else
			div.style.background = '#FFF';
	}

	// Show image
	function imgpreview(url) {
		dsDyn.message.init('<img src="'+url+'" alt="No image available." style="max-width:700px; max-height:700px;" />', true, undefined, 'darkbg', 'on');
	}

	// Change showdays on your uploaded images
	function yourimage_activate(id) {
		var span	= document.getElementById(id);
		var div1	= document.getElementById('yourimage_1day');
		var div2	= document.getElementById('yourimage_3days');
		var div3	= document.getElementById('yourimage_7days');
		var second	= document.getElementById('yourimage_second');
		var third	= document.getElementById('yourimage_third');
		
		// Removes the color
		div1.style.fontWeight	= '100';
		div1.style.color		= '#444';
		div2.style.fontWeight	= '100';
		div2.style.color		= '#444';
		div3.style.fontWeight	= '100';
		div3.style.color		= '#444';
		
		// Adds the color
		span.style.fontWeight	= '700';
		span.style.color		= '#336699';
		
		// Open more images
		if(span == div1) {
			second.style.display	= 'none';
			third.style.display		= 'none';
		} else if(span == div2) {
			second.style.display	= 'block';
			third.style.display		= 'none';
		} else if(span == div3) {
			second.style.display	= 'block';
			third.style.display		= 'block';
		}
	}
	
	// Makes the donation key form change
	function toUnicode(elmnt,content) {
		if (content.length==elmnt.maxLength) {
			next = elmnt.tabIndex
			if (next<document.forms[0].elements.length) {
				document.forms[0].elements[next].focus()
			}
		}
	}
	
	// Checks for valid email
	function isValidEmail(str) {
		return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
	}
	
	// Checks for valid date format (dd.mm.yyyy)
	function isValidDate(str) {
		return (str.indexOf(".") == 2) && (str.length == 10);
	}
	
	// Open & Close div with arrow
	function divWithArrow(id, buttonid) {
		div		= document.getElementById(id);
		div2	= document.getElementById(buttonid);
		if(div.style.display == 'none') {
			div.style.display = '';
			div2.innerHTML = '&uarr;';
		} else {
			div.style.display = 'none';
			div2.innerHTML = '&darr;';
		}
	}
	
	// Open div onclick
	function openDiv(id, input) {
		div		= document.getElementById(id);
		if(input.length >= 1) {
			div.style.display = '';
		}
	}
	
	// Adds information from page via ajax
	function addData(url, id) {
		div = document.getElementById(id);
		if(div.title == '') {
			$.get(url, function(data) {
				div.innerHTML = data;
			});
			div.title = 'loaded';
		}
	}
	
	// Random string
	function makeid() {
		var text = "";
		var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

		for( var i=0; i < 7; i++ )
			text += possible.charAt(Math.floor(Math.random() * possible.length));

		return text;
	}
	
	// ALL JQUERY FUNCTIONS
	$(function () {
		// The newsticker
		$('#infoText').list_ticker({
			speed:5000,
			effect:'slide'
		});
	
		// The uploader
		$('#startUploads').click(function () {
			$('.file_upload_start button').click();
		});
		$('#file_upload').fileUploadUI({
			uploadTable			: $('#fileList'),
			downloadTable		: $('#fileList'),
			dropZone			: $('#imgDragon'),
			url					: 'process.php?subAPI=mainsite',
			method				: 'POST',
			fieldName			: 'imagefile[]',
			previewAsCanvas		: true,
			formData			: [
									{name:'randomLocation', value:randomnumber=Math.floor(Math.random()*5)},
									{name:'groupUpload', value:makeid()}, 
									{name:'usubmit', value:true}
								],
			onComplete		 	: function(event, files, index, xhr, handler) {
									handler.onCompleteAll(files);
								},
			buildUploadRow		: function (files, index) {
									var fileNameIEString = files[index].name;
									fileNameIE	= fileNameIEString.split("\\");
									return $('<tr><td class="file_upload_preview" title="'+files[index].name+'"><!--[if IE]>'+fileNameIE[fileNameIE.length-1]+'<![endif]--></td>' +
											'<td class="file_upload_progress"><div></div></td>' +
											'<td class="file_upload_start"><button class="ui-state-default ui-corner-all" title="Start Upload"><span class="ui-icon ui-icon-circle-arrow-e">Start Upload</span></button></td>' +
											'<td class="file_upload_cancel"><button class="ui-state-default ui-corner-all" title="Cancel"><span class="ui-icon ui-icon-cancel">Cancel</span></button></td></tr>');
								},
			beforeSend			: function (event, files, index, xhr, handler, callBack) {
									handler.uploadRow.find('.file_upload_start button').click(callBack);
								},
			onChange			: function (event) {
									$("#imgDragon").fadeOut(500);
									$("#infoText").fadeOut(500);
									$("#likebuttons").fadeOut(500);
									$("#imageTypes_Preview").fadeOut(500);
									$("#startUploads").fadeIn(500);
								},
			onDrop				: function (event) {
									$("#imgDragon").fadeOut(300);
									$("#infoText").fadeOut(300);
									$("#likebuttons").fadeOut(300);
									$("#imageTypes_Preview").fadeOut(300);
									$("#startUploads").fadeIn(300);
								},
			onDocumentDragOver	: function (event) {
									$("#imgDragon").fadeIn(1000);
								},
			onCompleteAll		: function (files) {
									if (!files.uploadCounter) {
										files.uploadCounter = 1;  
									} else {
										files.uploadCounter = files.uploadCounter + 1;
									}
									if (files.uploadCounter === files.length) {
										window.location = "?viewLast=view";
									}
								}
		});
	});
	
	// Drag and drop
	var isChrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
	var isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
	if(isChrome || isFirefox) {
		$("#imgDragon").fadeIn(500);
	}
	
	$("img.lazy").lazyload({ 
		//effect:"fadeIn"
	});
