
jQuery(document).ready(function ()
{
	$('#topbox1').each(function ()
	{
		// inic
		var topsztori = $(this)
		var max_indx = 2
		topsztori.attr('data-index', 0)
		$('.links', topsztori).css({'z-index': 1000});
		$('.links_bg', topsztori).css({'z-index': 990});
		// process
		topsztori_change = function ( direct_index )
		{
			if( !topsztori.stoped || direct_index !== false )
			{
				prev_indx = parseInt(topsztori.attr('data-index'));
				indx = (direct_index !== false) ? direct_index : prev_indx+1;
				if( indx > max_indx ) indx = 0
				$('.images img', topsztori).css({position: 'absolute', 'z-index': 50});
				$('.images img', topsztori).eq(prev_indx).css({'z-index': 75});
				$('.images img', topsztori).eq(indx).css({'z-index': 100});
				$('.images img', topsztori).eq(indx).hide().fadeTo(250, 1);
				$('.images img', topsztori).eq(indx).css('cursor', 'pointer'); 
				$('.images img', topsztori).eq(indx).click(function ()
				{
					window.location.href = $('.links .item', topsztori).eq(indx).attr('href');
				});
				$('.links_bg div', topsztori).stop().fadeTo(250, 0.8);
				$('.links_bg div', topsztori).eq(indx).stop().fadeTo(250, 1);
//				$('.links a', topsztori).stop().fadeTo(250, 0.6);
//				$('.links a', topsztori).eq(indx).stop().fadeTo(250, 0.9);
				$('.links a', topsztori).css({'color': '#4495D1'});
				$('.links a', topsztori).eq(indx).css({'color': '#DB7701'});
				
				topsztori.attr('data-index', indx)
			}
		}
		// useractive
		$('.links a', topsztori).hover(function ()
		{
			topsztori.stoped = true
			topsztori_change( $(this).index() )
			topsztori.stoped = true
		}
		,function ()
		{
			topsztori.stoped = false
		});
		// auto
		topsztori_change(0)
		setInterval( "topsztori_change(false)", 3250 );
	});
	
	$('a').each(function ()
	{
		if( $(this).attr('href') && $(this).attr('href').substr(0, 4) == 'http' && -1 == $(this).attr('href').indexOf('koloknet.hu') )
		{
			$(this).attr('target', '_blank');
		}
		
		/* switch( $(this).attr('rel') )
		{
			case 'print' : 
				$(this).click(function ()
				{
					$('#head, #right, #left, #sidebar, #footer, #form_comment, div.share').hide();
					$('#container').css( {margin: '10px', width: '90%'} );
					$('#content').css( {width: '90%'} );
					$('body').css( {'background-color': '#FFFFFF'} );
					$(this).hide();
					window.print();
					return false;
				});
			break;
		} */
	});
	$('img.print').css({'cursor':'pointer'});
	$('img.print').click(function ()
	{
		$('#head, #right, #left, #sidebar, #footer, #form_comment, div.share').hide();
		$('#container').css( {margin: '10px', width: '90%'} );
		$('#content').css( {width: '90%'} );
		$('body').css( {'background-color': '#FFFFFF'} );
		$(this).hide();
		window.print();
		return false;
	});
	
	
})

// old js

// top menu
function tmenu_over(id)
{
	// var p = Position.positionedOffset($('tmenu_'+id));
	var p = $('#tmenu_'+id).offset();
	// var w = Element.getWidth($('tmenu_'+id));
	var w = $('#tmenu_'+id).width();
	if( $('#tmenu_child_'+id).text() )
	$('#tmenu_child_'+id).css({
		display: 'block',
		position: 'absolute',
		'z-index': '1000',
		'white-space': 'nowrap',
		width: 'auto',
		top: p.top+22+'px',
		left: p.left-10+'px'
	});
	if( $('#tmenu_child_'+id).width() < w )
	{
		$('#tmenu_child_'+id).css({
			width: w+1+'px'
		});
	}
}
function tmenu_out(id)
{
	 $('#tmenu_child_'+id).css({
		display: 'none'
	});
}

$(function()
{
	// menü, menu 
	$('#lmenu .sub, #tmenu .sub').css({
		display: 'none',
		position: 'absolute',
		'z-index': 2000,
		opacity: 0
	});
	$('#lmenu, #tmenu').each(function ()
	{
		var is_tmenu = ( $(this).attr('id') == 'tmenu' )
		var menu = $(this)
		$('.first a', menu).each(function ()
		{
			$(this).hover(function ()
				{
					var o = $(this).offset()
//					if(typeof(console) !== 'undefined') console.log(); 
					var to_x = o.left + 130
					var to_y = o.top-0
					var indx = $(this).index() - 0
					if( is_tmenu )
					{
						to_x = o.left + $(this).width() - 60;
						to_y = o.top+30;
					}
					if( $('.sub .body div.items div:eq('+indx+')', menu).text() )
					{
						if( $('.sub', menu).css('opacity') == 0 ) $('.sub', menu).css({opacity: 1, top:to_y, left:to_x})
					    $('.sub', menu).show();
					    $('.sub', menu).animate(
					    {
							    top: to_y,
							    left: to_x
					    }, 
					    {duration: 100} ); 
					
					    $('.sub .body div.items div', menu).each(function ()
					    {
						    if( $(this).index() == indx ) $(this).show()
						    else $(this).hide()
					    });
					}
					else $('.sub', menu).hide()
				}, 
				function () {
					// $('#lmenu .sub').hide();
				}
			);
		})
		menu.hover(
			function () {
				// $('#lmenu .sub').show();
			}, 
			function () {
				$('.sub', menu).hide();
			}
		);	
	})
	// karácsonyi novella oldal
	if( -1 < location.pathname.indexOf('497-melyiket-a-kilenc-kzl') )
	{
		$('#content').css({'background-color':'#f3fceb','background-image':'url(/theme_koloknet/images/kbg.gif)','background-position':'right top','background-repeat':'no-repeat'});
		$('#content h1').css({'font-weight':'bold','margin-top':'5px'});
		$('#article').css({'font-family':'Georgia','margin':'5px'});
		$('#article p').css({'font-size':'11px',color:'#003300','line-height':'20px'});
		$('#article .lead').css({'font-family':'Arial','font-size':'10px','line-height':'18px',display:'none'});
		$('#article #printmail .fr').css({'font-family':'Arial'});
		var email_print_link_content = $('#article #printmail span').html();
		$('#article #printmail').html('<span class="fr">'+email_print_link_content+'</span>');
	}

	//checkbox grouping
		$("input[class='selectgroup']").click(function() {
			if($(this).attr('checked')) {
				$("#" + $(this).attr('rel') + " input[type='checkbox']").attr('checked', true);
		} else {
				$("#" + $(this).attr('rel') + " input[type='checkbox']").attr('checked', false);
			}
		});

	// tabs
	  // $('#paneltabs > ul').tabs();
	  // $('#articlestabs > ul').tabs();
	  // $('#contentbartabs1 > ul').tabs();
	  // $('#contentbartabs2 > ul').tabs();
	//  $('#contentbartabs3 > ul').tabs(2);


	$('.styleswitch').click(function()
	{
		switchStylestyle(this.getAttribute("rel"));
		return false;
	});


	// target blank replacement
		if (!document.getElementsByTagName) return;
		var anchors = jQuery("#article p a");
		for (var i=0; i<anchors.length; i++) {
			var anchor = anchors[i];
			anchor.target = "_blank";
		}

		var anchors = jQuery(".appendix a");
		for (var i=0; i<anchors.length; i++) {
			var anchor = anchors[i];
			anchor.target = "_blank";
		}

  $('a[rel*=facebox]').facebox(); 

	$('#select_temaink_small').change(function() {
		if (jQuery('#select_temaink_small').val() != 0) {
		jQuery.facebox(function($) {
			  jQuery.get('/irjonnekunk', { tema: jQuery('#select_temaink_small').val() }, function(data) {
			    jQuery.facebox(data);
			  });
		});
	}
	});


	$('#select_szakerto_small').change(function() {
		if (jQuery('#select_szakerto_small').val() != 0) {
			jQuery.ajax({
			  type: "GET",
			  url: '/users/expert/' + jQuery('#select_szakerto_small').val(),
			  dataType: "script"
			});
		}
	});

	/* $('#polls_select').change(function(){
		if(jQuery('#polls_select').val() != "szavazások"){
			// $('#poll_answers').html('Betöltés...');
			$.get('/?index&block_id=34&view=null&answers='+jQuery('#polls_select').val(), '', function ( data ){
				$('#poll_answers').html(data);
			} ,'html');
		}
	}); */
	$('div.box.pool a.korabbi_temak').toggle(function ()
	{
		$('div.box.pool div.korabbi_temak').show(200);
	},
	function ()
	{
		$('div.box.pool div.korabbi_temak').hide(200);
	})
	
	$('div.box.pool div.korabbi_temak a').click(function ()
	{
		var h = $('#poll_answers').height();
		$('#poll_answers').html('<p>Betöltés...</p>');
		$('#poll_answers p').height(h);
		$.get('/?index&block_id=34&view=null&answers='+jQuery(this).attr('data-id'), '', function ( data ){
			$('#poll_answers').html(data);
		} ,'html');
		return false;
	})
	
	$('#poll_submit').click(function(){
		var checked = jQuery('input[name=poll_answer]:checked').val()
		if(checked != undefined){
			$.get('/?index&block_id=34&view=null&answer='+checked, '', function ( data ){
				$('#poll_answers').html(data);
			} ,'html');
		}
		return false;
	});
	
	
	$('#select_szakerto').change(function() {
		if (jQuery('#select_szakerto').val() != 0) {
		window.location.href = '/?felhasznalok&user_id='+$(this).val()
			// jQuery.facebox(function($) {
					// jQuery.get('/?kerdesek&kuldes_szak&view=null', function(data) {
					// jQuery.facebox(data);
				  // });
			// });
		}
	});
	
	/* ISKOLAKERESŐ, MEGYE-VÁROS SZŰRŐ */

	$('#school_megye').change(function() {
		if(jQuery('#school_megye').val() != "%") {
			jQuery.ajax({
				type: "GET",
			  url: '/schools/get_cities/?megye=' + jQuery('#school_megye').val(),
			  dataType: "script"
			});
		}
	});

	$('#schoollocation_megye').change(function() {
		if(jQuery('#schoollocation_megye').val() != "%") {
			jQuery.ajax({
				type: "GET",
			  url: '/schoollocations/get_cities/?megye=' + jQuery('#schoollocation_megye').val(),
			  dataType: "script"
			});
		}
	});
	
	$('a').each(function ()
	{
		if( $(this).attr('href') && $(this).attr('href').substr(0, 4) == 'http' && -1 == $(this).attr('href').indexOf('koloknet.hu') )
		{
			$(this).attr('target', '_blank');
		}
	});
	
});

function switchStylestyle(styleName)
{
        $('link[@rel*=style][@title]').each(function(i)
        {
                this.disabled = true;
                if (this.getAttribute('title') == styleName) this.disabled = false;
        });
//        createCookie('style', styleName, 365);
}


function emptyCommentForm(){
	$('comment_title').value = '';
	$('comment_content').value = '';
}
function faceboxReload(){
  $('div#recent_expert a[rel*=facebox]').facebox(); 
}

function setValIfVal(obj, val, new_val)
{
	if(obj.val() == val) obj.val(new_val);
}


/*
 * 	Easy Slider - jQuery plugin
 *	written by Alen Grakalic	
 *	http://cssglobe.com/post/3783/jquery-plugin-easy-image-or-content-slider
 *
 *	Copyright (c) 2009 Alen Grakalic (http://cssglobe.com)
 *	Dual licensed under the MIT (MIT-LICENSE.txt)
 *	and GPL (GPL-LICENSE.txt) licenses.
 *
 *	Built for jQuery library
 *	http://jquery.com
 *
 */
 
/*
 *	markup example for $("#images").easySlider();
 *	
 * 	<div id="images">
 *		<ul>
 *			<li><img src="images/01.jpg" alt="" /></li>
 *			<li><img src="images/02.jpg" alt="" /></li>
 *			<li><img src="images/03.jpg" alt="" /></li>
 *			<li><img src="images/04.jpg" alt="" /></li>
 *			<li><img src="images/05.jpg" alt="" /></li>
 *		</ul>
 *	</div>
 *
 */

(function($) {

	$.fn.easySlider = function(options){
	  
		// default configuration properties
		var defaults = {
			prevId: 		'prevBtn',
			prevText: 		'Previous',
			nextId: 		'nextBtn',
			nextText: 		'Next',
			step_px: 		'',
			step_px: 		'',
			show_length: 		'',
			orientation:	'', //  'vertical' is optional;
			speed: 			800,
			slideing_calback_fnc: function ()
			{
				
			}
		}; 
		
		var options = $.extend(defaults, options);  
		
		return this.each(function()
		{
			var obj = $(this); 
			var s = $(".slider ul li", obj).length;
			var w = obj.width(); 
			var ws = obj.children('.slider').width(); 
			var h = obj.height(); 
			var ts = s-((options.show_length) ? options.show_length : 1);
			var t = 0;
			var prev_p = null;
			var vertical = (options.orientation == 'vertical');
			var images_all_w = 0;
			var inactivate_next = false;
			var step_px = ( options.step_px ) ? options.step_px : ws;
			var step_py = ( options.step_py ) ? options.step_py : h;
				
			
			$("ul li", obj).each(function ()
			{
				images_all_w += $(this).width() + parseInt($(this).css('padding-left')) + parseInt($(this).css('padding-right'));
			});
			// $("ul", obj).css('width',s*w);
			$("ul", obj).css({width:images_all_w} );
			
			if( window.location.href.indexOf('#'+options.keep_to_next_page) > -1 )
			{
				var slider_location_spl = window.location.href.split('#'+options.keep_to_next_page);
				t = parseInt(slider_location_spl[1])
				keep()
			}
			
			if(!vertical) $("li", obj).css('float','left');
			
			$("#"+options.nextId).click(function()
			{
				if (t>=ts || inactivate_next)
				{
					$(this).css('cursor', 'default');
					$(this).fadeTo(250, 0.4);
				}else{
					animate("next");
				}
				$("#"+options.prevId).fadeTo(250, 1);
				$("#"+options.prevId).css('cursor', 'pointer');
				return false;
			});
			$("#"+options.prevId).click(function()
			{
				if (t<=0)
				{
					$(this).css('cursor', 'default');
					$(this).fadeTo(250, 0.4);
				}else{
					animate("prev");
				}
				inactivate_next = false
				$("#"+options.nextId).fadeTo(250, 1);
				$("#"+options.nextId).css('cursor', 'pointer');
				return false;
				
			});	
			function animate(dir)
			{
				if(dir == "next")
					 t = (t>=ts) ? ts : t+1;
				else t = (t<=0) ? 0 : t-1;
				
				if( options.keep_to_next_page )
				{
					$("ul li a",obj).each(function ()
					{
						if( !$(this).attr('orig_href') )
						{
							$(this).attr('orig_href', $(this).attr('href'));
						}
						$(this).attr('href', $(this).attr('orig_href')+'#'+options.keep_to_next_page+t);
					})
				}
				
				if(!vertical)
				{
					var p = (t*step_px*-1);
					if( p+$("ul",obj).width()-w < 0 )
					{
						p = -$("ul",obj).width()+ws
						t--;
						inactivate_next = true
					}
					$("ul",obj).animate( { marginLeft: p }, options.speed );
				}else{
					var p = (t*step_py*-1);
					$("ul",obj).animate( { marginTop: p }, options.speed );
				}
				if( options.slideing_calback_fnc) eval('options.slideing_calback_fnc()');
			};
			function keep()
			{
				if( options.keep_to_next_page )
				{
					$("ul li a",obj).each(function ()
					{
						if( !$(this).attr('orig_href') )
						{
							$(this).attr('orig_href', $(this).attr('href'));
						}
						$(this).attr('href', $(this).attr('orig_href')+'#'+options.keep_to_next_page+slider_location_spl[1]);
					})
				}
				
				if(!vertical)
				{
					var p = (t*step_px*-1);
					if( p+$("ul",obj).width()-w < 0 )
					{
						p = -$("ul",obj).width()+ws
						// t--;
						inactivate_next = true
					}
					$("ul",obj).css( { marginLeft: p } );
				}else{
					var p = (t*step_py*-1);
					$("ul",obj).css( { marginTop: p } );
				}
				if( options.slideing_calback_fnc) eval('options.slideing_calback_fnc()');
			}
			// if(s>1) $("#"+options.nextId).fadeIn();
		});
	};

})(jQuery);

