function loadjscssfile(filename, filetype){
 if (filetype=="js"){ //if filename is a external JavaScript file
  var fileref=document.createElement('script')
  fileref.setAttribute("type","text/javascript")
  fileref.setAttribute("src", filename)
 }
 else if (filetype=="css"){ //if filename is an external CSS file
  var fileref=document.createElement("link")
  fileref.setAttribute("rel", "stylesheet")
  fileref.setAttribute("type", "text/css")
  fileref.setAttribute("href", filename)
 }
 if (typeof fileref!="undefined")
  document.getElementsByTagName("head")[0].appendChild(fileref)
}

/* MAIN MENU */

$(document).ready(function(){
	imgpath = 'files/shared/';
	$("#nicemenu img.arrow").click(function(){ 
								
		$("span.head_menu").removeClass('active');
		
		submenu = $(this).parent().parent().find("div.sub_menu");
		
		if(submenu.css('display')=="block"){
			$(this).parent().removeClass("active"); 	
			submenu.hide(); 		
			$(this).attr('src', imgpath + 'arrow_hover.png');									
		}else{
			$(this).parent().addClass("active"); 	
			submenu.fadeIn(); 		
			$(this).attr('src',imgpath + 'arrow_select.png');	
		}
		
		$("div.sub_menu:visible").not(submenu).hide();
		$("#nicemenu img.arrow").not(this).attr('src',imgpath + 'arrow.png');
						
	})
	.mouseover(function(){ $(this).attr('src',imgpath + 'arrow_hover.png'); })
	.mouseout(function(){ 
		if($(this).parent().parent().find("div.sub_menu").css('display')!="block"){
			$(this).attr('src',imgpath + 'arrow.png');
		}else{
			$(this).attr('src',imgpath + 'arrow_select.png');
		}
	});

	$("#nicemenu span.head_menu").mouseover(function(){ $(this).addClass('over')})
								 .mouseout(function(){ $(this).removeClass('over') });
	
	$("#nicemenu div.sub_menu").mouseover(function(){ $(this).fadeIn(); })
							   .blur(function(){ 
							   		$(this).hide();
									$("span.head_menu").removeClass('active');
								});		
								
	$(document).click(function(event){ 		
			var target = $(event.target);
			if (target.parents("#nicemenu").length == 0) {				
				$("#nicemenu span.head_menu").removeClass('active');
				$("#nicemenu div.sub_menu").hide();
				$("#nicemenu img.arrow").attr('src',imgpath + 'arrow.png');
			}
	});   
								   
});

window.onload=function(){
	Nifty("div.stylized","big");
	Nifty("div.curved","big");
	Nifty("div.J1","normal same-height");
	fixHeight();
}

/* jQuery Tabs */
$(function() {
	$('#tabs').tabs({ 
		fx: { opacity: 'toggle' },
		show: function(event, ui) { 
			fixPhaseHeight();
			fixHeight()
		}
	});
});

function fixHeight() {
	    var cH = $('#contentcolumn').outerHeight(true);
		var tH = $('#rightcolumn').outerHeight(true);
		if(tH > cH) {
		$('#contentcolumn').height(tH);
		};
}

function fixPhaseHeight() {
	if( $('#phasedays').length ) {
		var pH = $('#phasedays').outerHeight(true);
		$('#holdfazis_elorejelzes').height(pH + 20);
	}
}

//fix jQuery
$.uicornerfix('6px');

/* Scroll To TOP */
jQuery.fn.topLink = function(settings) {
		settings = jQuery.extend({
			min: 1,
			fadeSpeed: 200,
			ieOffset: 50
		}, settings);
		return this.each(function() {
			//listen for scroll
			var el = $(this);
			el.css('display','none'); //in case the user forgot
			$(window).scroll(function() {
				if(!jQuery.support.hrefNormalized) {
					el.css({
						'position': 'absolute',
						'top': $(window).scrollTop() + $(window).height() - settings.ieOffset
					});
				}
				if($(window).scrollTop() >= settings.min)
				{
					el.fadeIn(settings.fadeSpeed);
				}
				else
				{
					el.fadeOut(settings.fadeSpeed);
				}
			});
		});
	};
	
	$(document).ready(function() {
		$('#top-link').topLink({
			min: 400,
			fadeSpeed: 500
		});
		//smoothscroll
		$('#top-link').click(function(e) {
			e.preventDefault();
			$.scrollTo(0,300);
		});
	});

function bookmark() {
	bookmarkurl="http://www.vadaszlesen.hu"
	bookmarktitle="Vadász-lesen"
	if (document.all)
	window.external.AddFavorite(bookmarkurl,bookmarktitle)
	else if (window.sidebar) // firefox
	window.sidebar.addPanel(bookmarktitle, bookmarkurl, "");
}