jQuery(document).ready(function(){
	jQuery('#foglaloLoader').ajaxStart(function(){
		jQuery(this).fadeIn('fast');
	});

	jQuery('#foglaloLoader').ajaxComplete(function(){
		jQuery(this).fadeOut('fast');
	});
});


function tinyInit(w, h){
	a = typeof(a) != 'undefined' ? a : 0;
  b = typeof(b) != 'undefined' ? b : 0;

  tinyMCE.init({
    theme : "advanced",
    plugins: "phpimage, media, paste, table",
    mode : "textareas",
    width: 800-w,
    height: 300-h,
    skin : "o2k7",
    skin_variant: "black",
    forced_root_block : '',
    force_p_newlines : true,
    content_css: "/css/tiny.css",
    convert_urls: false,
		theme_advanced_buttons1 : "pastetext,bold,italic,underline,|,justifyleft,justifycenter,justifyright,justifyfull,|,fontselect,|,bullist,numlist,|,outdent,indent,|,undo,redo,|,link,unlink,|,sub,sup,|,code,phpimage,media",
		theme_advanced_buttons2 : "tablecontrols",
		theme_advanced_buttons3 : "",
    theme_advanced_toolbar_location : "top",
    theme_advanced_toolbar_align : "center",
    theme_advanced_path : false,
    theme_advanced_containers_default_align : "center"
  });
}

function shadowboxInit(){
	Shadowbox.init({
		overlayColor:	'#000000',
		overlayOpacity:	0.8,
		fadeDuration: 0.3,
		initialHeight: 50,
		initialWidth: 50,
		resizeDuration: 0.3,
		enableKeys:false,
		viewportPadding: 5,
    onClose: function(){window.location.reload();}
	});
}

function shadowboxInitTable(){
	Shadowbox.init({
		overlayColor:	'#000000',
		overlayOpacity:	0.8,
		fadeDuration: 0.3,
		initialHeight: 50,
		initialWidth: 50,
		resizeDuration: 0.3,
		enableKeys:false,
		viewportPadding: 5,
    onClose: function(){window.location.reload();}
	});
}

function openEdit(school, type, week){
	Shadowbox.open({
		player: 'iframe',
   	content: url='/admin/tables/edit/'+school+'/'+type+'/'+week+'',
   	title: 'Szerkesztés',
   	width: 400,
    height: 235
  });
}

function boxOpen(url){
	Shadowbox.open({
		player: 'iframe',
   	content: url='/generals/seoEdit/'+url+'',
   	title: 'Szerkesztés',
   	width: 650,
    height: 235
  });
}

function boxOpenLinks(){
	Shadowbox.open({
		player: 'iframe',
   	content: url='/generals/linksEdit/',
   	title: 'Szerkesztés',
   	width: 800,
    height: 500
  });
}

function comment(school_id){
	Shadowbox.open({
		player: 'iframe',
   	content: url='/comments/add/'+school_id+'',
   	title: 'Iskola értékelése',
   	width: 650,
    height: 400
  });
}

function anythingSliderInit(name1, name2, name3, name4){
	var slider2 = [name1, name2, name3, name4];
	function formatText(index, panel) {
		return slider2[index - 1];
	}
	
	jQuery(document).ready(function(){
		jQuery('.anythingSlider').anythingSlider({
	    easing: "swing",               
	    autoPlay: false,               
	    startStopped: false,           
	    delay: 3000,                   
	    animationTime: 600,            
	    hashTags: false,                
	    buildNavigation: true,         
	    pauseOnHover: true,            
	    startText: "Start",            
	    stopText: "Stop",               
	    navigationFormatter: formatText,
	    forwardText: '',
	    backText: ''      
		});
	});
}

function checkType(id){
	jQuery(document).ready(function(){
		if(document.getElementById('Price'+id+'Check').checked){
			jQuery('#typePriceNote'+id).slideDown();
		} else {
			jQuery('#typePriceNote'+id).slideUp();
		}
  });
}

function checkAcc(id){
	jQuery(document).ready(function(){
		if(document.getElementById('Acc'+id+'Mealcheck').checked){
			jQuery('#accPriceNote'+id).slideDown();
		} else {
			jQuery('#accPriceNote'+id).slideUp();
		}
  });
}

function checkAccMeal(id){
	jQuery(document).ready(function(){
		if(document.getElementById('Acc'+id+'Roomcheck').checked){
			jQuery('#accMeal'+id).slideDown();
		} else {
			jQuery('#accMeal'+id).slideUp();
		}
  });
}

function schoolOpenClose(id){
	jQuery(document).ready(function(){
		if(document.getElementById('resultSchool'+id).style.display=='none'){
			jQuery('[id*=resultSchool]').slideUp();
			jQuery('#resultSchool'+id).slideDown();
		} else {
			jQuery('#resultSchool'+id).slideUp();
		}
  });
}

function openClose(id){
	jQuery(document).ready(function(){
		if(document.getElementById(id).style.display=='none'){
			jQuery('#'+id).slideDown();
		} else {
			jQuery('#'+id).slideUp();
		}
  });
}

function datePicker(field, born){
	field = typeof(field) != 'undefined' ? field : 'SearchDate';
	born = typeof(born) != 'undefined' ? born : 0;
	
	jQuery.tools.dateinput.localize("hu", {
		months: 'Január,Február,Március,Április,Május,Június,Július,Augusztus,Szeptember,Október,November,December',
		shortMonths:  'Jan,Feb,Márc,Ápr,Máj,Jún,Júl,Aug,Szept,Okt,Nov,Dec',
		days:         'vasárnap,hétfő,kedd,szerda,csütörtök,péntek,szombat',
		shortDays:    'V,H,K,Sze,Cs,P,Szo'
	});
	jQuery("#"+field).unbind();
	if(born==1){
		jQuery(document).ready(function(){

			jQuery("#"+field).dateinput({
				yearRange: [-80, 1],
				firstDay: 1,
				format: 'yyyy-mm-dd',
				lang: 'hu',
				selectors: true,
				offset: [-15, -8]
			})
		});
	} else {
		jQuery(document).ready(function(){	
			jQuery("#"+field).dateinput({
				firstDay: 1,
				format: 'yyyy-mm-dd',
				lang: 'hu',
				selectors: true,
				offset: [-15, -8],
				yearRange: [0, 5],
				min: 0
			})
		});
	}
}

function validError(){
	jQuery('.error-message').fadeIn(500).delay(2000).fadeOut(2000);
}

function validErrorSchool(){
	jQuery('.error-message').css('margin-left', '19px');
	jQuery('.error-message').fadeIn(500).delay(2000).fadeOut(2000);
}

function kepfel(uid){
	jQuery(document).ready(function(){
    jQuery('#kepInput').uploadify({
        'uploader': '/js/uploadify/uploadify.swf',
        'script': "/generals/kepUploadSale/"+uid,
        'folder': '/img/tartalom/sales/small',
        'cancelImg': '/js/uploadify/cancel.png',
        'fileExt':"*.jpg;*.gif;*.png",
        'fileDesc':"JPG, GIF, PNG files",
        'auto':true,
        'multi':false,
        'width': 108,
        'sizeLimit': 15728640,
        'buttonText': "",
        'buttonImg': '/js/uploadify/kepbut.gif',
        'onComplete': function(event, queueID, fileObj, response, data) {
	        response=jQuery.parseJSON(response);
            jQuery('#uploadCompleteKep').html('<div class="uploadifyQueueItem" style="line-height: 50px; height: 50px"><span style="float:left">Feltöltve: '+response.name+' </span> <span style="float:right"><img src="'+response.fpath+'" height="50px" style="float: right"/></span></div>');
            document.getElementById('SaleKep').value=''+response.fpath+'';
        },
        'onError': function(event, queueID, fileObj, errorObj) {
            jQuery('#uploadCompleteKep').append('Hiba: '+errorObj.info+' <br />');
        }
    });
	});
}

function kepfelMulti(model, folder, uid){
	jQuery(document).ready(function(){
    jQuery('#kepInput').uploadify({
        'uploader': '/js/uploadify/uploadify.swf',
    		'script': '/generals/kepUpload/'+uid+'/'+folder+'',
        'folder': '/img/tartalom/'+folder+'/small',
        'cancelImg': '/js/uploadify/cancel.png',
        'fileExt':"*.jpg;*.gif;*.png",
        'fileDesc':"JPG, GIF, PNG files",
        'auto':true,
        'multi':true,
        'width': 108,
        'sizeLimit': 15728640,
        'buttonText': "",
        'buttonImg': '/js/uploadify/kepbut.gif',
        'onComplete': function(event, queueID, fileObj, response, data) {
	        response=jQuery.parseJSON(response);
            jQuery('#uploadCompleteKep').append('<div class="uploadifyQueueItem" style="line-height: 50px; height: 50px"><span style="float:left">Feltöltve: '+response.name+'&nbsp;&nbsp;</span> <span style="float:right"><img src="'+response.fpath+'" height="50px" style="float: right"/></span></div>');
            fajlfelAppend(''+response.fpath+'', ''+model+'Kep');
        },
        'onError': function(event, queueID, fileObj, errorObj) {
          jQuery('#uploadCompleteKep').append('Hiba: '+errorObj.info+' <br />');
        }
    });
	});
}

function fajlfelAppend(value, divId){
	obj=document.getElementById(''+divId+'');
	if(obj.value==''){
		var tomb={};
		tomb[''+value+'']=value;
		son=JSON.stringify(tomb);
		obj.value=son;
	} else {
		var tomb=JSON.parse(obj.value);
		tomb[''+value+'']=value;
		son=JSON.stringify(tomb);
		obj.value=son;
	}
}

function fajlfelDelete(value, divId, span){
	obj=document.getElementById(''+divId+'');
	var tomb=JSON.parse(obj.value);
	delete tomb[''+value+''];
	son=JSON.stringify(tomb);
	obj.value=son;
	document.getElementById(''+span+'').innerHTML='<span style="color: red">Törölve</span>';
}

function actionText(id){
	jQuery(document).ready(function(){
		obj=document.getElementById('action-text');
		if(obj.style.display=='none'){
			jQuery('#action-text').html('<div id="action-panel-close" onclick="actionClose();"></div>'+jQuery('#actionTextHidden'+id).html()+'').fadeIn();
		} else {
			jQuery('#action-text').fadeOut('fast').html('<div id="action-panel-close" onclick="actionClose();"></div>'+jQuery('#actionTextHidden'+id).html()+'').fadeIn('fast');
		}
	});
}

function actionClose(){
	jQuery(document).ready(function(){
		jQuery('#action-text').fadeOut();
	});
}

function actionBackground(url){
	jQuery(document).ready(function(){
		jQuery('#action').css('background-image', 'url('+url+')');
	});
}

function dropdownIn(){
  jQuery(document).ready(function(){
      jQuery('#dropdown').slideDown();
  });
}
function dropdownOut(){
  jQuery(document).ready(function(){
      jQuery('#dropdown').slideUp();
  });
}


jQuery(document).ready(function() {
	if(jQuery('.scrollable').length){
		jQuery(".scrollable").scrollable();
	}

});



