$(document).ready(function(){
 
	$('body').append('<div style="display:none;" id="OVERLAY" onclick="javascript: closeUzklausa();"></div><div style="display:none;" id="WINDOW"><table class="shi" cellpadding="0" cellspacing="0"><tr class="t"><td class="l"></td><td class="m"></td><td class="r"></td></tr><tr class="m"><td class="l"></td><td class="m" id="WINDOW_content"><table border="0" cellpadding="0" cellpadding="0" width="100%"><tr><td><b style="margin-bottom:3px;" id="uzklausa_top_text">'+phrases_uzklausa_top_text+'</b></td><td align="right"><a href="javascript: void(closeUzklausa());">'+phrases_uzklausa_close+'<a></td></tr></table><div id="uzklausa_content"><iframe src="http://update.easywebmanager.com/anketa.php?id=6051&s=adme" width="100%" height="500" frameborder="0"></iframe></div></td><td class="r"></td></tr><tr class="b"><td class="l"></td><td class="m"></td><td class="r"></td></tr></table></div><div style="display:none;" id="PRELOADER"></div>');

	$('a[rel]').lightBox();

	//$('#menu li a').mouseover(function(){ $(this).animate({'background':"#000000"}, 500, function(){} );  } );
	//$('#menu li a').mouseout(function(){ $(this).animate({background:'none'}, 500, function(){} );  });

	$('#menu li').click(function(){ $('#menu li').attr('class',''); $(this).attr('class','active'); });

	
	$('#menu li').each(function(){
		ahref = $(this).find('a');
		$(this).html("<span>"+ahref.html()+"</span>"+$(this).html());
	});	


	SWFAddress.addEventListener(SWFAddressEvent.CHANGE, loadPage );
	initLinks();

	/*$('.easy_slideshow').each(function(){
		speed = parseInt($(this).attr('speed'));
		$(this).find('a').fadeOut(0);
		$(this).find('.index_0').fadeIn(1000);
		$(this).everyTime(parseInt($(this).attr('speed')), function(i){ index=i%$(this).find('a').length; $(this).find('a').fadeOut(1000); $(this).find('.index_'+index).fadeIn(1000); });
	});*/ 
	
	if(location.hash=='#kainos') showUzklausa();

	prepare();
  
});

function prepare(){

	$('#content .portfolio_ .c').mouseover(function(){ $(this).find(".desc").stop(true, false).animate({top:$(this).find(".portfolio").height()-$(this).find(".desc").height()-14+'px'}, 500, function(){} );  } );
	$('#content .portfolio_ .c').mouseout(function(){ $(this).find(".desc").stop(true, false).animate({top:$(this).find(".portfolio").height()+'px'}, 500, function(){} );  });


	$('#title_img').height($('#title').height()-3);
	$('#title_img').width($('#title').width());

	$('#rightblock p').height($('#title').height()-23);	

	$('#rightblock_img').height($('#rightblock').height()-3);
	$('#rightblock_img').width($('#rightblock').width()+$('#title').width()+45);

}


function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}




function showUzklausa(){
	
	$('#uzklausa_top_text').html(phrases_uzklausa_top_text);
	$('#uzklausa_content').html('<iframe src="http://update.easywebmanager.com/anketa.php?id=6051&s=adme" width="100%" height="500" frameborder="0"></iframe>');

	$('#OVERLAY').show();
	$('#WINDOW').width(670);
	$('#WINDOW').css('top','150px');
	$('#WINDOW').css('left', parseInt(f_clientWidth()/2) - parseInt($('#WINDOW').width()/2) + 'px');
	$('#WINDOW').show();

}

function closeUzklausa(){
	$('#OVERLAY').hide();
	$('#WINDOW').hide();	
}


function show_easy_module(id){
	
	//$("#mod_"+id).css('left', link_obj.position().left + 'px');
	//$("#mod_"+id).css('top', link_obj.position().top + link_obj.height() + 'px');

	//$(".mod_desc").hide();
	//$("#mod_"+id).show();	

	$('#uzklausa_top_text').html($("#mod_title_"+id).html());
	$('#uzklausa_content').html($("#mod_"+id).html());

	$('#OVERLAY').show();
	$('#WINDOW').width(700);
	$('#WINDOW').css('top', '150px');
	$('#WINDOW').css('left', parseInt(f_clientWidth()/2) - parseInt($('#WINDOW').width()/2) + 'px');
	$('#WINDOW').show();

}

function showTemplateItem(id, title, lng){
	
	$.ajax({
		type:'get',
		url:'xml.php?get=getTemplate&id='+id+'&lng='+lng,
		success: function(html){
			$('#uzklausa_top_text').html(title);
			$('#uzklausa_content').html(html);

			$('#OVERLAY').show();
			$('#WINDOW').width(900);
			$('#WINDOW').css('top','50px');
			$('#WINDOW').css('left', parseInt(f_clientWidth()/2) - parseInt($('#WINDOW').width()/2) + 'px');
			$('#WINDOW').show();
		}
	});


}


function showTemplateForm(id, title, lng){

	$.ajax({
		type:'get',
		url:'ajax.php?content=getTemplateForm&id='+id+'&tpl='+title+'&lng='+lng,
		success: function(html){
			$('#uzklausa_top_text').html(title);
			$('#uzklausa_content').html(html);

			$('#OVERLAY').show();
			$('#WINDOW').width(500);
			$('#WINDOW').css('top','50px');
			$('#WINDOW').css('left', parseInt(f_clientWidth()/2) - parseInt($('#WINDOW').width()/2) + 'px');
			$('#WINDOW').show();
		}
	});

}

function showQuestionForm(title, lng){

	$.ajax({
		type:'get',
		url:'ajax.php?content=getQuestionForm&title='+title+'&lng='+lng,
		success: function(html){
			$('#uzklausa_top_text').html(title);
			$('#uzklausa_content').html(html);

			$('#OVERLAY').show();
			$('#WINDOW').width(500);
			$('#WINDOW').css('top','150px');
			$('#WINDOW').css('left', parseInt(f_clientWidth()/2) - parseInt($('#WINDOW').width()/2) + 'px');
			$('#WINDOW').show();
		}
	});

}

function postQuestionForm(form, title, lng){
	
	$.ajax({
		type:'post',
		url:'ajax.php?content=getQuestionForm&title='+title+'&lng='+lng,
		data:formData2QueryString(form),
		success: function(html){
			//$('#uzklausa_top_text').html(title);
			$('#uzklausa_content').html(html);

			/*
			$('#OVERLAY').show();
			$('#WINDOW').width(500);
			$('#WINDOW').css('top','50px');
			$('#WINDOW').css('left', parseInt(f_clientWidth()/2) - parseInt($('#WINDOW').width()/2) + 'px');
			$('#WINDOW').show();
			*/
		}
	});
}


function postTplOrderForm(form, id, title, lng){

	$.ajax({
		type:'post',
		url:'ajax.php?content=getTplOrderForm&id='+id+'&title='+title+'&lng='+lng,
		data:formData2QueryString(form),
		beforeSend: function(){
			$('#PRELOADER').show();
	  	},
		success: function(html){
			$('#tpl_order_form_content').html(html);
			$('#PRELOADER').hide();
		}
	});
}



function formData2QueryString(docForm) {

        var strSubmit       = '';
        var formElem;
        var strLastElemName = '';
        
        for (i = 0; i < docForm.elements.length; i++) {
                formElem = docForm.elements[i];

                switch (formElem.type) {
                        // Text, select, hidden, password, textarea elements
                        case 'text':
                        case 'hidden':
                        case 'password':
                        case 'textarea':
				formElem.value = formElem.value.replace(/&/g, '%26');
				formElem.value = formElem.value.replace(/\+/g, '%2B');
				strSubmit += formElem.name + '=' + formElem.value + '&';
                        break;
                        case 'select-one':
                        	strSubmit += formElem.name + '=' + escape(formElem.options[formElem.selectedIndex].value) + '&';
                        break;
                        case 'checkbox':
                        	if(formElem.checked == true) strSubmit += formElem.name + '=' + escape(formElem.value) + '&';
                        break;
                        case 'radio':
	                        if(formElem.checked == true) strSubmit += formElem.name + '=' + escape(formElem.value) + '&';
                }
        }
        return strSubmit;
}


function submitSearchForm(url, form){
	location = url + document.forms['search'].elements['q'].value;
}

function getMouseXY(e) {
  if (document.all) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
  return { x:tempX, y:tempY }
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return { x:curleft, y:curtop };
}

function showPostForm(obj){
	document.getElementById('NL_overlay').style.display = 'block';
	document.getElementById(obj).style.display = 'block';
	try{
		document.getElementsByTagName("html")[0].style.overflow = "hidden";
	}catch(e){}
}

function closePostForm(obj){
	
	clearPostForm(obj);
	
	document.getElementById('NL_overlay').style.display = 'none';
	document.getElementById(obj).style.display = 'none';
	try{
		document.getElementsByTagName("html")[0].style.overflow = "";
	}catch(e){}
}

function clearPostForm(obj){
	document.getElementById(obj + '_form').reset();
}



