function gotoURL(url)
{
	window.location.href = url;
}

function goBack()
{
	history.go(-1);
	return false;
}

function logout()
{
	document.logout_form.logout.value=1;
	document.logout_form.submit();
}

function reloadImage(id, mysrc)
{
	var rand_value = Math.floor(Math.random()*200);
	document.getElementById(id).src=mysrc+'?'+rand_value;
}

function confirmMsg(msg)
{
	return confirm(msg) || false;
}

function changeLang(lid)
{
	gotoURL(document.getElementById('lang_link_'+lid).href);
}

function isEmptyString(str)
{
	return (str.replace(/\s/gi, '') == '');
}

function isEmptyObject(obj)
{
	for(var i in obj)
		return false;
	return true;
}

function genRandom(length)
{
	var s = '';
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	var randomstring = '';
	for (var i=0; i<length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		s += chars.substring(rnum,rnum+1);
	}
	return s;
}

function bindHomeActions()
{
	$('#blocksHome a, .smallBlock a, .subMenuItem a, #newsTitle a, #sendBtn, #resetBtn')
	.mouseenter(function(){
		$(this).contents().filter('img.hidden').stop(true, true).fadeIn(300, "linear");
	})
	.mouseleave(function(){
		$(this).contents().filter('img.hidden').stop(true, true).fadeOut(300, "linear");
	});
	DD_belatedPNG.fix('.blockL img, .blockR img, #newsTitle img, .smallBlock img, .subMenuSep, #logoDiv, h1 img, #leftDivHome, img.bullet, #portfolio_navigation .slider, #portfolio_navigation .button, #portfolio_images img, .imageflow img');
}

function reload_image(id, mysrc)
{
	var rand_value = Math.floor(Math.random()*200);
	document.getElementById(id).src=mysrc+'?'+rand_value;
}

function initImageFlowGallery(id)
{
	var startIndex = 1
	var $imgs = $('#'+id+' img')
		.attr('alt', function(){return $(this).data('title');})
		.each(function(index){
			if($(this).data('selected'))
				startIndex = index+1;
		});
	var instanceOne = new ImageFlow();
	var imageFlowConfig = { ImageFlowID: id,
						reflectPath: _abroot_url,
						buttons: true,
						startID: startIndex,
 						glideToStartID: false,
						//circular: true,
						//aspectRatio: 1.618,
						//reflectionP: 0.4, 
						//imagesHeight: 0.7,
						imageFocusM: 1.7,
						//imageFocusMax: 2,
						imagesM: 1.5,
						//xStep:75,
						imageCursor: 'pointer',
						onClick: function() {
							loadPage(this.url);
						} 
					};
	if(!$.browser.msie || $.browser.version.substr(0,1)>=7)
	{
		imageFlowConfig['reflectionPNG'] = true;
		imageFlowConfig['reflectionGET'] = '&fade_start=25%';
		imageFlowConfig['reflectionP'] = 0.5;
	}
	else
	{
		//imageFlowConfig['reflections'] = false;
	}
	instanceOne.init(imageFlowConfig);
}

globals.temp.contentList = new Array();
function loadPage(url)
{
	setPageContent(globals.lang.loading);
	$.get(_ajax_url+'text.php',
		{
			url: url.replace(_abroot_url, ''),
			l: globals.params.lang
		},
		function(data) {
			setPageContent(data.html, true);
		},
		'json'
	);
}

function setPageContent(html, t)
{
	$cnt = $('#mainContent');
	if(globals.temp.contentList.length > 1)
		globals.temp.contentList.pop();
	globals.temp.contentList.push(html);
	if(!t)
	$cnt.slideUp(400, function(){
		$(this).html(globals.temp.contentList.shift());
		/*$cnt.height($cnt.height());
		var h = $(this).show().height();
		console.log(h)
		$(this).css({height: 0}).animate({height: h+'px'}, 400);*/
	});
	else
	$cnt.html(globals.temp.contentList.shift());
	$cnt.slideDown(400);
}

function submitForm(name, set)
{
	$('form[name='+name+']').append('<input type="hidden" name='+set+' value="1" />').submit();
}

function resetForm(name)
{
	document.forms[name].reset();
}

function initFancybox()
{
	$('div.slider img').each(function(index){
		var $t = $(this);
		var sid = $t.parent().attr('id');
		var $wrapper = $('<a />').attr({href: $t.attr('src'), title:$t.attr('alt'), rel:sid});
		$t.wrap($wrapper);
		var fancyConf = {
			'overlayShow'	: true,
			'transitionIn'	: 'fade',
			'transitionOut'	: 'fade',
			'speedIn' : 400,
			'speedOut' : 300,
			'padding' : 20,
			'titlePosition':'inside',
			'titleFormat': function(title, currentArray, currentIndex, currentOpts) {
				return '<span id="fancybox-title-over">' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
			}
		};
		$t.parent().css('position', 'absolute').fancybox(fancyConf);
		if(index > 0)
			$t.parent().hide();
		else
			$t.parent().parent().css({width: $t.parent().width(), height: $t.parent().height()});
	});
}


