/*

####################################################################

	* Origin		: www.dontbetonit.co.uk
	* File name		: javascript/scripts.js
	* Author		: Piotr Dziembor
	* Modified		: 13:47 14/02/2010
	* Copyrights	: www.dontbetonit.co.uk

####################################################################

*/

	// CSS Browser Selector v0.3.5.1 modified for Firefox 3.6 - Rafael Lima (http://rafael.adm.br) | http://rafael.adm.br/css_browser_selector | License: http://creativecommons.org/licenses/by/2.5/ | Contributors: http://rafael.adm.br/css_browser_selector#contributors
	function css_browser_selector(u){var ua = u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1;},g='gecko',w='webkit',s='safari',o='opera',h=document.documentElement,b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3.6')?g+' ff3 ff3_6':is('firefox/3.5')?g+' ff3 ff3_5':is('firefox/3')?g+' ff3':is('gecko/')?g:is('opera')?o+(/version\/(\d+)/.test(ua)?' '+o+RegExp.$1:(/opera(\s|\/)(\d+)/.test(ua)?' '+o+RegExp.$2:'')):is('konqueror')?'konqueror':is('chrome')?w+' chrome':is('iron')?w+' iron':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?'mobile':is('iphone')?'iphone':is('ipod')?'ipod':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win':is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; css_browser_selector(navigator.userAgent);

	var contact = null;
	
	// Contact form slider
	
	function show_contact(position, time) {
		
		if (contact == null) { Effect.SlideDown('contact_form', { duration: 2.0 }); contact = 'opened'; setTimeout("Effect.ScrollTo('" + position + "')", time); } else { Effect.SlideUp('contact_form', { duration: 0.5 }); contact = null; }
		
	}
	
	// Image swap / rollover function
	
	function swap_image(btn_id, btn_src) {
	
		document.getElementById(btn_id).src = btn_src;
	
	}

	// News bottom navigation - hints
	
	function sttn(text) {
	
		if (text != "") document.getElementById('ntnext').innerHTML = text; else document.getElementById('ntnext').innerHTML = '<br \/>';
	
	}
	
	// Redirections editor [panel]
	
	function edit_red(id, vin, vout)
	{
	
		document.getElementById('ed_in_' + id).style.display = 'none';
		document.getElementById('ed_ot_' + id).style.display = 'none';
		document.getElementById('ed_sv_' + id).style.display = 'none';
		
		document.getElementById('edp_in_' + id).style.display = 'block';
		document.getElementById('edp_ot_' + id).style.display = 'block';
		document.getElementById('edp_sv_' + id).style.display = 'block';
		
		document.getElementById('edv_in_' + id).value = vin;
		document.getElementById('edv_ot_' + id).value = vout;
	
	}
	
	// Clear contact form
	
	function clearcf()
	{
	
		document.getElementById('contact_name').value = '';
		document.getElementById('contact_email').value = '';
		document.getElementById('contact_phone').value = '';
		document.getElementById('contact_msg').value = '';
	
	}
	
	// Send contact form
	
	function sendform()
	{
		var xmlHttp = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject ('MSXML2.XMLHTTP.3.0');
		
		var url = "sendform.php";
		
		var fname = document.getElementById('contact_name').value;
		var fphon = document.getElementById('contact_phone').value;
		var fmail = document.getElementById('contact_email').value;
		var fmesg = document.getElementById('contact_msg').value;
		var urlpg = document.getElementById('puid').value;
		
		var fmesg_r = new RegExp("\n", 'g');
		fmesg = fmesg.replace(fmesg_r, '---');
		
		var urlpg_r = new RegExp("=", 'g');
		urlpg = urlpg.replace(urlpg_r, '');
		
		url = url + "?fname=" + fname + "&fphon=" + fphon + "&fmail=" + fmail + "&fmesg=" + fmesg + "&urlpg=" + urlpg + "&sid=" + Math.random();
		
		xmlHttp.open ('GET', url, true);
		xmlHttp.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
		
		$('contact_res').appear({ duration: 0.3 });
		
		document.getElementById('contact_res').innerHTML = '<div style="margin-top: 80px; font-family: Trebuchet MS; font-size: 16px; letter-spacing: 1px; text-align: center; color: #fff;"><img src="images/loading.png" title="Loading..." alt="Loading..." style="border: 0; margin-bottom: -2px;" margin-right: 5px;\/> Please wait while sending the message ...<\/div>';
		xmlHttp.onreadystatechange = function()
		{
			if (xmlHttp.readyState == 4 && (xmlHttp.status == 200 || xmlHttp.readyState == 'complete'))
			{
				
				document.getElementById('contact_res').innerHTML = xmlHttp.responseText;
				
			}
		}
		xmlHttp.send (null);
	}
	
	function elhighlight(element, chclass)
	{
	
		document.getElementById(element).className = chclass;
		document.getElementById('s'+element).className = chclass+'_shadow';
	
	}
	
	function clearbox(element, text)
	{
	
		if (document.getElementById(element).value == text) document.getElementById(element).value = '';
		else if (document.getElementById(element).value == '') document.getElementById(element).value = text;
	
	}
	
	function rollover(element, image)
	{
	
		document.getElementById(element).src = '/images/'+image;
	
	}
	
	function pageWidth() { return window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null; }
	function pageHeight() { return window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null; }
	
	// Popup window

	var newWin = null;
	function close_window(){
		if (newWin != null){
			if(!newWin.closed)
				newWin.close();
		}
	}
	
	function new_window(strURL,strType,strHeight,strWidth) {
	
		close_window();
		
		var pw = Math.round(pageWidth()/2)-Math.round(strWidth/2);
		var ph = Math.round(pageHeight()/2)-Math.round(strHeight/2);
		
		var strOptions = '';
		
		if (strType=="console") strOptions="location,scrollbars,resizable,height="+strHeight+",width="+strWidth;
		if (strType=="fixed") strOptions="status,height="+strHeight+",width="+strWidth;
		if (strType=="scrolled") strOptions="scrollbars,height="+strHeight+",width="+strWidth;
		if (strType=="elastic") strOptions="toolbar,menubar,scrollbars,resizable,location,height="+strHeight+",width="+strWidth;
		
		strOptions += ',left=' + pw + ',top=' + ph + ',screenX=' + pw + ',screenY=' + ph;
		
		newWin = window.open(strURL, 'newWin', strOptions);
		newWin.focus();
	
	}
	
	// Select and get path
	
	function get_path(path_l, path_g, name)
	{
	
		if (document.getElementById('code_box_wrapper').style.display == 'block') document.getElementById('code_box_wrapper').style.display = 'none';
		if (document.getElementById('pic_box_wrapper').style.display == 'block') document.getElementById('pic_box_wrapper').style.display = 'none';
		if (document.getElementById('path_box_wrapper').style.display == 'none') document.getElementById('path_box_wrapper').style.display = 'block';
		
		var box_l = document.getElementById('path_box_l');
		var box_g = document.getElementById('path_box_g');
		var box_u = document.getElementById('path_box_url');
		
		box_l.value = path_l;
		box_g.value = path_g;
		
			if (name != "")
			{
			
				if (document.getElementById('path_box_url_wrapper').style.display == 'none') document.getElementById('path_box_url_wrapper').style.display = 'block';
				
				box_u.value = '<a href="' + path_l + '">' + name + '</a>';				
				box_u.focus();
				box_u.select();
			
			} else {
			
				box_l.focus();
				box_l.select();
			
			}
		
		setTimeout("Effect.ScrollTo('bottom')", 50);
	
	}
	
	// Show picture code
	
	function insert_pic_code(size, path, ext, mdhash, fileloc)
	{
	
		var fpath;
		if (size != "orginal") fpath = '/' + path + 'cache/' + size + '_' + mdhash + '.jpg';
		else fpath = '/' + fileloc;
		
		document.getElementById('pic_box_code').value = fpath;
		document.getElementById('pic_box_code_full').value = '<img src="' + fpath + '" alt="ALT_TEXT_HERE" title="TITLE_TEXT_HERE" \/>';
		document.getElementById('pic_box_code_full').focus();
		document.getElementById('pic_box_code_full').select();
	
	}
	
	// Generate HTML code for the file
	
	function get_code(path, ext, mdhash, fileloc)
	{
	
		if (document.getElementById('path_box_wrapper').style.display == 'block') document.getElementById('path_box_wrapper').style.display = 'none';
		
		if (ext == "jpg" || ext == "jpeg" || ext == "gif" || ext == "png")
		{
		
			if (document.getElementById('code_box_wrapper').style.display == 'block') document.getElementById('code_box_wrapper').style.display = 'none';
			if (document.getElementById('pic_box_wrapper').style.display == 'none') document.getElementById('pic_box_wrapper').style.display = 'block';
			
			var pict = document.getElementById('pic_box_thumbs');
			
			pict.innerHTML = '';
			
			pict.innerHTML += '<table cellpadding="0" border="0" cellspacing="10" class="thumb_prev">'
			+ '<tr><td style="text-align: center;">Small</td><td style="text-align: center;">Medium</td><td style="text-align: center;">Large</td><td style="text-align: center;">Original</td><\/tr><tr>'
			+ '<td style="text-align: center;"><img src="/' + path + 'cache/small_' + mdhash + '.jpg" style="cursor: pointer;" onclick="insert_pic_code(\'small\', \'' + path + '\', \'' + ext + '\', \'' + mdhash + '\', \'' + fileloc + '\')" \/><\/td>'
			+ '<td style="text-align: center;"><img src="/' + path + 'cache/medium_' + mdhash + '.jpg" style="cursor: pointer;" onclick="insert_pic_code(\'medium\', \'' + path + '\', \'' + ext + '\', \'' + mdhash + '\', \'' + fileloc + '\')" \/><\/td>'
			+ '<td style="text-align: center;"><img src="/' + path + 'cache/big_' + mdhash + '.jpg" style="cursor: pointer;" onclick="insert_pic_code(\'big\', \'' + path + '\', \'' + ext + '\', \'' + mdhash + '\', \'' + fileloc + '\')" \/><\/td>'
			+ '<td style="text-align: center;"><img src="/' + fileloc + '" style="max-width: 340px; cursor: pointer;" onclick="insert_pic_code(\'orginal\', \'' + path + '\', \'' + ext + '\', \'' + mdhash + '\', \'' + fileloc + '\')" \/><\/td>'
			+ '<\/tr><\/table><br \/><input id="pic_box_code_full" class="configarea_long" value="Select some picture to see HTML code here" \/><br \/><br \/><input id="pic_box_code" class="configarea_long" value="Select some picture to see it\'s path here" \/>';
		
		} else {
		
		if (document.getElementById('pic_box_wrapper').style.display == 'block') document.getElementById('pic_box_wrapper').style.display = 'none';
		if (document.getElementById('code_box_wrapper').style.display == 'none') document.getElementById('code_box_wrapper').style.display = 'block';
		
		var code = document.getElementById('code_box');
		
		var filearr = fileloc.split('/');
		var filename = filearr[filearr.length-1];
		
		code.value = '<a href="/' + fileloc + '">' + filename + '</a>';
		code.focus();
		code.select();
		
		}
		
		setTimeout("Effect.ScrollTo('bottom')", 1000);
	
	}
