var ajaxFile="/includes/ajax.php";

$().ready(function(){

	$('.filterbar > div.textfield').click(function(){
		modul=$(this).attr('id').replace('_title','');
		
		//osszes box elrejtese
		$('.popupbox:not(#'+modul+'_popupbox)').hide('slow');		
		
		//az aktualis megjelenitese
		$('#'+modul+"_popupbox").show('slow');		
		
		
	});
	
	$('.filterbar > #btn_search').click(function() {
		var kereses = false;
        $('.filterbar > input:hidden').each(function() {
            if ($(this).val()) {
                kereses=true;
            }
        });

        if( kereses && !isEngSite() ) {
			$('.popupbox:not(#newstype_popupbox)').hide('slow');		
			
			$('#newstype_popupbox').show('slow');		
        }
		else if( kereses && isEngSite() ){
			window.location.href = submitSearch();
		}
		else {
            return false;
        }    
    });
	
	// link esemeny beallitasda
	$('div.padder_div:not(#news_padder) > a').bind('click',setLinkMod);

	$('div#news_padder > a').bind('click', submitSearch );
	
	//mezok torlese
	$('.btn_clr').bind('click',mezoTorles);
	
	//boxok bezarasa
	$('a.close').bind('click',boxHidden);
		
	//kezo
	getBoxs('service');
	
});


function submitSearch()
{
	var query= isEngSite() ? '/en/news/?kereses' : '/hireink/?kereses';

	$('.filterbar > input:hidden').each(function() {
		if ($(this).val()) {
			query+='&'+$(this).attr('name')+'='+$(this).val();
		}
	});
	switch ( $(this).attr('name') )	{
		case '1':
			$(this).attr('href',query + '&type=1');
			break;
		case '2':
			$(this).attr('href', query.replace('hireink', 'sajtokozlemeny') + '&type=2');
			break;
		default:
			$(this).attr('href',query);
			break;	
	}
	$("a.close:first").trigger('click');
	return query;
}


//box elrejti
function boxHidden(){
	$('.popupbox').hide('slow');
}


//torli a keresomezok tartalmat
function mezoTorles(){
		
	id=$(this).attr('id');
	modul=id.replace('clear_','');
	
	$("#"+modul+"_title").empty();
	$("#"+modul+"_input").val('');
	
	getBoxs(modul);

}


//beallitja a padderen beluli linkek viselkedeset
function setLinkMod(){
	
	parentId=$(this).parent().attr('id');
	id=parentId.replace('_padder','');
	linkTartalom=$(this).attr('id');
	linkTartalom=linkTartalom.replace('links_','');
	
	$("#"+id+"_title").text( $(this).text() );
	$("#"+id+"_input").val( linkTartalom );
	
	
	
	$("a.close:first").trigger('click');
	
	getBoxs(id);
	return false;
}

//az ajax stringet rakja ossze
function makeBoxQuery(modul){
	query=ajaxFile;
	query+="?return="+modul;	
	//query+="?lekerdezes";
	$('.filterbar > input:hidden').each(function() {
		if ($(this).val()) {
			query+='&'+$(this).attr('name')+'='+$(this).val();
		}
    });
	return query;
}

//ajax kerest hajtja vegre
function getBoxs(aktModul){	
	
	ajaxQuery=makeBoxQuery(aktModul);
	
	//alert(ajaxQuery);
	$.post(ajaxQuery,{
		modul:'popupbox',
		lang: isEngSite() ? 'en' : 'hu'
	},function(html){
		//alert(html);
		setBoxs(html);
	});
	
	
}
//az eredmenyt allitja be
function setBoxs(html){
	
	$('div.padder_div > a').unbind('click',setLinkMod);	
		
	tomb=html.split("##separator##");
	for(i=0;i<tomb.length;i++){
		if(tomb[i]=="##no_data##"){
			newVal="";
		}
		else{
			newVal=tomb[i];
		}
		
		$('.padder_div:eq('+i+')').not('#news_padder').html(newVal);
	}	
	
	$('div.padder_div:not(#news_padder) > a').bind('click',setLinkMod);	
}





 

/**********/
/* galery */
/**********/

$().ready(function(){
	$('.galery_kiskep').click(function(){
		imgSrc=$(this).attr('src');
		imgSrc=imgSrc.replace('_thumb','');
		$('#galery_nagykep').attr('src',imgSrc);
	});
});


$().ready(function(){
	kepek = $('#galery_kiskep_sor > img').size();
	// 100 px a kep és 25 px a margin-right
	szelesseg= parseInt( 1.1 * kepek * 125 );
	$('#galery_kiskep_sor').css('width',szelesseg+"px");	
});

/*
$().ready(function(){
	szelesseg=0;	
	$('.galery_kiskep').each(function(){
		szelesseg+=parseInt(this.width + 20);
	});
	szelesseg+=50;
	$('#galery_kiskep_sor').css('width',szelesseg);
});
*/






