/**
 * @package WordPress
 * @subpackage Dehír portál (http://www.dehir.hu/)
 * @since Dehir 1.0
 */
 
var changetime = 9000;
var changetotimeout;
var changeable = true;
 
function changeto(id) {
	if (!id) { id = $('div.featured li.active').attr('id').replace(/hir_/g, ''); id++; }
	if (id > $('div.featured ul.featured').children().size()) id = 1;
	
	if ((changeable) && ($('div.featured li.active').attr('id').replace(/hir_/g, '') != id)) {
		clearTimeout(changetotimeout);
		changeable = false;
		
		$('div.featured div.elem.active div.top').stop().animate({'top': '-32px', 'opacity' : 0}, { duration: 400, queue: false});
		$('div.featured div.elem.active div.bottom').stop().animate({'left' : '-440px', 'opacity' : 0}, { duration: 400, queue: false, complete: function() {
			$('div.featured div.elem.active').fadeOut('normal', function() {
				
				$('div.featured div.elem.active div.bottom').css({'left' : 0, 'opacity' : 1});
				$('div.featured div.elem.active div.top').css({'top': 0, 'opacity' : 1});
				
				$(this).removeClass('active');
				
				$('div.featured div#elem_' + id + ' div.bottom').css({'left' : '-440px', 'opacity' : 0});
				$('div.featured div#elem_' + id + ' div.top').css({'top' : '-32px', 'opacity' : 0});
				
				$('div.featured div#elem_' + id).fadeIn('normal', function() {
					$(this).find('div.top').stop().animate({'top': 0, 'opacity' : 1}, { duration: 400, queue: false});
					$(this).find('div.bottom').stop().animate({'left' : 0, 'opacity' : 1}, { duration: 400, queue: false});
				}).addClass('active');
				
				changetotimeout = setTimeout('changeto()', changetime);
				changeable = true;
			});
		}});
		
		$('div.featured li.active').removeClass('active');
		$('div.featured li#hir_' + id).addClass('active');
	}
}

function addtofavorites(title, url) {

	if (window.sidebar)
		window.sidebar.addPanel(title, url, "");
	else if (window.external)
		window.external.AddFavorite( url, title);
	else if (window.opera && window.print)
		return true;
}

jQuery(document).ready(function($) {
	
	if ($('div.featured').length > 0) changetotimeout = setTimeout('changeto()', changetime);

	if ($('body.wp-admin').length > 0) { // HA AZ ADMINBAN VAN
	
		$('div[id*=_dehir-widget-] input#savewidget').live('click', function() {
			var tipus = $(this).parents('form').find('input.blokktipus:checked').attr('value').replace(/blokk_/g, '');
			$(this).parents('form').find('div.tipus').hide();
			$(this).parents('form').find('div.block').removeClass('block');
			$(this).parents('form').find('div.' + tipus).show().addClass('block');
		});
		
		$('div[id*=_dehir-widget-] input.blokktipus').live('change', function() {
			var tipus = $(this).attr('value').replace(/blokk_/g, '');
			$(this).parents('form').find('div.tipus').hide();
			$(this).parents('form').find('div.block').removeClass('block');
			$(this).parents('form').find('div.' + tipus).show().addClass('block');
		});
		
		if ($('body.widgets-php').length > 0) {
			$('body.widgets-php div.widgets-holder-wrap.closed').removeClass('closed');
			$('div#widgets-right div.widgets-holder-wrap:eq(0)').addClass('moved').insertBefore('div#widgets-left div#available-widgets');
			$('div#widgets-right div.widgets-holder-wrap:eq(0)').addClass('moved').insertBefore('div#widgets-left div#available-widgets');
		}
		
		if (($('div.icon32-posts-page').length == 0) && ($('div.icon32-posts-videopost').length == 0) && ($('div.icon32-posts-match').length == 0) && ($('div.icon32-posts-dtvpost').length == 0)) {
			$('<div class="cikkoldal"></div>').insertAfter('div#titlediv');
			$('div.cikkoldal').html($('div#cikklead').html());
			$('<div class="cimoldal"></div>').insertBefore('div#titlediv');
			$('div#cikklead, div.cikkoldal h5').remove();
			//$('div#postimagediv div.inside').append($('div.featuredpic').html());
			//$('div.featuredpic').remove();
			
			$('div.cimoldal').html($('div#article_settings_main').html());
			$('div.cimoldal').prepend('<h2>Címoldal</h2>').find('h2').css({'margin': '0 0 10px 0', 'padding': 0});
			$('div.cimoldal').append('<h2>Cikkoldal</h2>').find('h2').css({'margin': '0 0 10px 0', 'padding': 0});
			$('div.cimoldal div.inside').css({'border-bottom': '1px solid #CCC', 'padding': '0 0 30px 0', 'margin': '0 0 20px 0'});
			$('div.cimoldal h3, div.cimoldal h5, div.cimoldal div.handlediv, div#article_settings_main').remove();
			
			$('input#title').attr('tabindex', 1);
			$('textarea#content').attr('tabindex', 5);
			$('input#publish').attr('tabindex', 6);
			$('ul#category-tabs li a, a#category-add-toggle, input.button.tagadd, input#save-post, input#post-preview, div#misc-publishing-actions a').attr('tabindex', 7);
		}
		
		if ($('div.icon32-posts-videopost').length != 0) {
			$('<div class="kaltura"></div>').insertBefore('div#titlediv');
			$('div.kaltura').html($('div.relatedsearch').html());
			$('div.relatedsearch').remove();
		}
	
		$('input#loadoptions').click(function() {
			$(this).addClass('loading');
			jQuery.post($('input#ajaxurl').val(), { action : 'video_infos', videoid : $('input#video_id').attr('value') }, function(response) {
				var infos = jQuery.parseJSON(response);
				$('label#title-prompt-text').click();
				$('input#title').attr('value', infos.name).blur();
				$('input#new-tag-post_tag').attr('value', infos.tags);
				$('input#video_views').attr('value', infos.views);
				$('span.views').html(infos.views);
				$('input.button.tagadd').click();
				$('input#new-tag-post_tag').blur();
				$('textarea#video_description').attr('value', infos.description);
				$('input#loadoptions').removeClass('loading');
			});
		});
	
		$('div#attach_related_articles input.button, table.newsletter input.button').click(function() {
			var newsletter = false;
			if ($(this).parents('table.newsletter').hasClass('newsletter')) newsletter = true;
			var search_keyword = $(this).parent().find('input#keyword').attr('value');
			$('div.related_result').html('').addClass('loading');
			jQuery.post($('input#ajaxurl').val(), { action: 'related_action', keyword : search_keyword, related : $('input#related_articles').attr('value'), postid : $('input#postid').attr('value'), hirlevel : newsletter}, function(response) {
				$('div.related_result').html(response).removeClass('loading');
			});
		});
		
		$('div.related_result div span').live('click', function() {
			var id = $(this).parents('div.result').attr('id').replace(/id_/g, '');
			$(this).html('-').addClass('minus').parents('div.result').hide().appendTo('.attached').fadeIn('fast');
			$('input#related_articles').attr('value', ($('input#related_articles').attr('value') + ',' + id).replace(/,,/g, ','));
		});
		
		$('div.attached div span.minus').live('click', function() {
			var id = $(this).parents('div.result').attr('id').replace(/id_/g, '');
			$(this).parents('div.result').fadeOut('fast', function() { $(this).remove(); });
			var related = $('input#related_articles').attr('value').split(',');
			var inputvalue = '';
			for(var i in related) {
				if ((related[i] != id) && (related[i] != '')) inputvalue += related[i] + ',';
			}
			inputvalue = inputvalue.replace(/,,/g, ',');
			$('input#related_articles').attr('value', inputvalue);
		});
		
		$('input#keyword').keypress(function(e) {
            code = (e.keyCode ? e.keyCode : e.which);
            if (code == 13) {
            	$('input#searchrelated').click();
            	e.preventDefault();
            }
        });
        
        $('input[name="sticky"]').parent().hide();
        
        $('a.editmatch').click(function() { $('div.matchdetails').slideToggle(); });
        $('a.cancel').click(function() { $('div.matchdetails').slideUp(); });
        
        $('a.matchdelete').click(function() {
			var del = confirm('Biztosan törli?');
			if (del) return true; else return false;
        });
        
        $('select#eventtype').change(function() {
        	if ($(this).attr('value') == 'substitute') $('select.player_2').show(); else $('select.player_2').hide();
        });
        
        $('input#article_head_color, input.colorpick').ColorPicker({
			onSubmit: function(hsb, hex, rgb, el) {
				$(el).val('#' + hex);
				$(el).ColorPickerHide();
			},
			onBeforeShow: function () {
				$(this).ColorPickerSetColor(this.value);
			}
		})
		.bind('keyup', function(){
			$(this).ColorPickerSetColor(this.value);
		});
		
		$('body.post-php form#post, body.post-new-php form#post').submit(function() {
			if ($('input#title').attr('value') == '') {
				$('img.ajax-loading').hide();
				alert('Nem adott meg címet a cikknek!');
				return false;
			}
		});
		
		$('li#menu-plugins').addClass('menu-top-first');
		if ($('li.toplevel_page_widgets').length != 0) {
			$('li.toplevel_page_widgets').insertAfter('li#menu-posts');
		}
		$('ul#adminmenu').css({'background' : 'transparent'});
		$('ul#adminmenu li').css({'opacity' : 1});
		
		if ($('li.toplevel_page_analytics').length != 0) {
			$('li.toplevel_page_analytics').insertAfter('li#toplevel_page_wpcf7');
			$('li.toplevel_page_analytics a').attr('href', 'http://www.google.com/analytics/').attr('target', 'blank');
		}
		
		$('a.addline').live('click', function() {
			$('table#subtitles').append('<tr><td><input autocomplete="off" type="text" name="hour[]" class="form-input-tip" value="00" style="width: 26px" /> :</td><td><input autocomplete="off" type="text" name="minute[]" class="form-input-tip" value="00" style="width: 26px" /> :</td><td><input autocomplete="off" type="text" name="second[]" class="form-input-tip" value="00" style="width: 26px" /></td><td><input autocomplete="off" type="text" name="text[]" maxlength="40" class="form-input-tip" style="width: 265px; font-size: 15px; font-weight: bold;" /><br/><input autocomplete="off" type="text" name="smalltext[]" maxlength="60" class="form-input-tip" style="width: 265px; font-size: 12px;" /></td><td><input autocomplete="off" type="text" name="duration[]" class="form-input-tip" value="10" style="width: 26px" /> mp</td><td><a class="delete delline">Törlés</a></td></tr>');
		});
		
		$('a.delline').live('click', function() {
			$(this).parents('tr').remove();
		});
		
		
		
		// MENÜ SZINEZÉS MEGOLDÁS
		var menuid = 1;
		$('div.menu-item-settings').each(function() {
			
			var colors = $(this).find('.edit-menu-item-attr-title').attr('value').split('-');
			
			$(this).append('<p class="description description-wide" style="margin-top: 20px">Típus:<br/><input type="radio" class="menutype texttype" name="menutype" id="id_' + menuid + '" /> <label for="id_' + menuid++ + '">Szöveg</label> <input type="radio" class="menutype picturetype" name="menutype" id="id_' + menuid + '" /> <label for="id_' + menuid++ + '">Kép</label> </p>');
			$(this).append('<p class="texttype description description-thin">Szöveg színe: <br/><input type="text" class="text colorpick widefat" /></p><p class="texttype description description-thin">Háttér színe: <br/><input type="text" class="background colorpick widefat" /></p>');
			$(this).append('<p class="picturetype description description-wide">Kép URL: <br/><input type="text" class="menuimage widefat" /></p>');
			
			if (colors[0] == 'szin') {
				$(this).find('input.text').attr('value', colors[1]);
				$(this).find('input.background').attr('value', colors[2]);
				$(this).find('p.picturetype').hide();
				$(this).find('input.menutype.texttype').attr('checked', true);
			} else if (colors[0] == 'kep') {
				$(this).find('input.menuimage').attr('value', decodeURI(colors[1]));
				$(this).find('p.texttype').hide();
				$(this).find('input.menutype.picturetype').attr('checked', true);
			}
			
			$(this).find('input.text').ColorPicker({
				onSubmit: function(hsb, hex, rgb, el) {
					colors = $(el).parents('div.menu-item-settings').find('.edit-menu-item-attr-title').attr('value').split('-');
					$(el).val(hex);
					$(el).parents('div.menu-item-settings').find('input.edit-menu-item-attr-title').val('szin-' + hex + '-' + colors[2]);
					$(el).ColorPickerHide();
				},
				onBeforeShow: function () {
					$(this).ColorPickerSetColor(this.value);
				}
			}).bind('keyup', function(){
				$(this).ColorPickerSetColor(this.value);
			});
			$(this).find('input.background').ColorPicker({
				onSubmit: function(hsb, hex, rgb, el) {
					colors = $(el).parents('div.menu-item-settings').find('.edit-menu-item-attr-title').attr('value').split('-');
					$(el).val(hex);
					$(el).parents('div.menu-item-settings').find('input.edit-menu-item-attr-title').val('szin-' + colors[1] + '-' + hex);
					$(el).ColorPickerHide();
				},
				onBeforeShow: function () {
					$(this).ColorPickerSetColor(this.value);
				}
			}).bind('keyup', function(){
				$(this).ColorPickerSetColor(this.value);
			});
			
		});
		
		$('input.menutype').live('change', function() {
			if ($(this).is(':checked')) {
				$(this).parents('div.menu-item-settings').find('p.texttype, p.picturetype').hide();
				$(this).parents('div.menu-item-settings').find('p.' + $(this).attr('class').replace(/menutype /g, '')).show();
			}
		});
		
		$('input.menuimage').live('change', function() {
			$(this).parents('div.menu-item-settings').find('input.edit-menu-item-attr-title').val('kep-' + encodeURI($(this).val()));
		});
		
		//$('input.edit-menu-item-attr-title').parents('p').hide();
		
		
		$('#sortable').sortable({
			placeholder: "sortactive",
			opacity: 0.8,
			revert: true,
			handle: '.handle',
			update: function(event, ui) {
				var results = $('#sortable').sortable('toArray');
				$('#galorder').val(results.toString());
				$('span.eq').each(function() {
					$(this).html(($(this).parents('li').index() + 1));
				});
			}
		});
		$('#sortable').disableSelection();
		
		if ($('div.wp-submenu a[href=admin.php?page=nggallery-order]').length != 0) {
			$('div.wp-submenu a[href=admin.php?page=nggallery-order]').parent().insertAfter($('div.wp-submenu a[href=admin.php?page=nggallery-add-gallery]').parent());
			$('div.wp-submenu a[href=admin.php?page=nggallery-manage-gallery]').hide();
		}
		
	}
		
		
		
	// Felhasználói felület	
		
	$('a.tab').each(function() {
		$(this).click(function() {
			$(this).parent().find('ul').hide().parent().find('a.active').removeClass('active');
			$(this).addClass('active').parent().find('ul.' + $(this).attr('id').replace(/tab_/g, '')).show();
		});
	});
	
	$('div.featured ul.featured li.hir').mouseover(function() {
		//clearTimeout(changetotimeout);
		var id = $(this).attr('id').replace(/hir_/g, '');
		//changeto(id);
		
		$('div.featured ul.featured li.active').removeClass('active');
		$('div.featured div.active').removeClass('active').css({'display': 'none'});
		$(this).addClass('active');
		$('div.featured div#elem_' + id).addClass('active').css({'display': 'block'});
	}).click(function() {
		var redir = $('div.featured ul.featured li.active h5 a').attr('href');
		window.location.href = redir;
	});
	
	$('div.featured').mouseout(function() {
		changetotimeout = setTimeout('changeto()', changetime);
	}).mouseover(function() {
		clearTimeout(changetotimeout);
	});
	
	$('div.videobox ul li, body.galeria div.thumbs div.loadframe').click(function() {
		var id = $(this).attr('id');
		$('div.videobox div.videos div.video').html('');
		jQuery.post($('input#ajaxurl').val(), { action: 'my_action', videoid : id}, function(response) {
			$('div.videobox div.videos div.video').html(response);
			$('div.videobox ul li.active, body.galeria div.thumbs div.active').removeClass('active');
			$('#' + id).addClass('active');
		});
	});
	
	$('a.logreg').click(function() {
		if ($('div.' + $(this).attr('id') + 'box').css('display') == 'block') {
			$('div.' + $(this).attr('id') + 'box').slideUp('fast');
			$('a.logreg').removeClass('active');
		} else {
			$('a.logreg').removeClass('active');
			$('div.registerbox, div.loginbox').hide();
			$('div.' + $(this).attr('id') + 'box').slideDown('fast');
			$(this).addClass('active');
		}
		return false;
	});
	
	$('div.article a.text#novel').click(function() {
		if (!($('div.article').hasClass('big')) && (!($('div.article').hasClass('small'))))
			$('div.article').addClass('big');
		else if (($('div.article').hasClass('small')))
			$('div.article').removeClass('small');
	});
	
	$('div.article a.text#csokkent').click(function() {
		if (!($('div.article').hasClass('big')) && (!($('div.article').hasClass('small'))))
			$('div.article').addClass('small');
		else if (($('div.article').hasClass('big')))
			$('div.article').removeClass('big');
	});
	
	$('div.leftarrow').mouseover(function() {
		var movetime = (($('.move-by-js').css('left').replace(/px/g,'')) * -8);
		$('.move-by-js').stop().animate({'left' : 0}, movetime, function() {
			$('div.leftarrow').removeClass('active');
		});
		$('div.rightarrow').addClass('active');
	}).mouseout(function() {
		if ($('.move-by-js').css('left') == '0px') $(this).removeClass('active');
		$('.move-by-js').stop();
	});
	
	$('div.rightarrow').mouseover(function() {
		var movetime = ($('.move-by-js').children().size() * 0.6 * 1000) - (($('.move-by-js').css('left').replace(/px/g,'')) * -8);
		var maxright = ($('.move-by-js').width() - $(this).parent().width()) * -1;
		$('.move-by-js').stop().animate({'left' : (maxright + 'px')}, movetime, function() {
			$('div.rightarrow').removeClass('active');
		});
		$('div.leftarrow').addClass('active');
	}).mouseout(function() {
		var maxright = ($('.move-by-js').width() - $(this).parent().width()) * -1;
		if ($('.move-by-js').css('left') == (maxright + 'px')) $(this).removeClass('active');
		$('.move-by-js').stop();
	});
	
	$('div.thumbs.inactive').hide();
	
	$('ul.thumbs').css({'width' : ($('ul.thumbs').children().size() * 146) + 'px'});
	
	if ($('ul.thumbs').length != 0) {
		if ($('ul.thumbs').children().size() <= 6) {
			$('div.rightarrow, div.leftarrow').remove();
		}
	}
	
	$('div.sidebar div.kiemelthirdetes').each(function() {
		var color = $(this).css('background-color');
		$(this).css({'background-color' : ''});
		$(this).parent().css({'background-color' : color});
	});
	
	$('a.togglethumbs').click(function() {
		$('div.thumbs').slideToggle();
		$(this).toggleClass('off');
	});
	
	$('a.toggleinfo').click(function() {
		$('p.informacio').slideToggle();
		$(this).toggleClass('off');
	});
	
	$('div.newsletter input.inp').each(function() {
		if ($(this).attr('value') == '')
			if ($(this).attr('name') == 'subscribe_name') $(this).attr('value', 'Név');
			else if ($(this).attr('name') == 'subscribe_email') $(this).attr('value', 'E-mail cím');
		$(this).focus(function() {
			if (($(this).attr('name') == 'subscribe_name') && ($(this).attr('value') == 'Név')) $(this).attr('value', '');
			if (($(this).attr('name') == 'subscribe_email') && ($(this).attr('value') == 'E-mail cím')) $(this).attr('value', '');
		}).blur(function() {
			if (($(this).attr('name') == 'subscribe_name') && ($(this).attr('value') == '')) $(this).attr('value', 'Név');
			if (($(this).attr('name') == 'subscribe_email') && ($(this).attr('value') == '')) $(this).attr('value', 'E-mail cím');
		});
	});
	
	$('a.player').live('mouseover mouseout', function() {
		if (event.type == 'mouseout')
			$(this).children().not('dehirplay').stop().animate({'opacity': '0.7'});
		else 
			$(this).children().not('dehirplay').stop().animate({'opacity': '1'});
	});
	
	/*$('ul.menu li a').each(function() {
		if ($(this).attr('title') != '') {
			var colors = $(this).attr('title').split('-');
			if (colors[0] == 'szin') {
				if (colors[1].match(/[0-9A-Fa-f]{6}/g)) {
					$(this).attr('title', '');
					$(this).css({'color' : '#' + colors[1] + ' !important', 'background' : '#' + colors[2] + ' !important'})
				}
			} else if (colors[0] == 'kep') {
				$(this).html('<img src="' + colors[1] + '" alt="" style="max-height: 30px" />')
			}
		}
	});*/
	
	$('div.sidebar div.calendar a.monthchange').click(function() { // Program oldali naptár kezelése
	
		var active = parseInt($('div.sidebar div.calendar div.active').attr('id').replace(/month_/g, ''));
		var ev = parseInt($('div.sidebar div.calendar div.active').attr('class').replace(/ev_/g, '').replace(/active/g, '').replace(/ /g, ''));
	
		if ($(this).attr('id') == 'prevmonth') {
		
			var prev = active - 1;
			if (prev < 1) {
				ev--;
				prev = 12;
			}
			
			if ($('div.ev_' + ev + '#month_' + prev).length > 0) {
				$('div.active').fadeOut('fast', function() {
					$(this).removeClass('active');
					$('div.ev_' + ev + '#month_' + prev).fadeIn('fast').addClass('active');
				});
			}
			
		} else if ($(this).attr('id') == 'nextmonth') {
		
			var next = active + 1;
			if (next > 12) {
				next = 1;
				ev++;
			}
		
			if ($('div.ev_' + ev + '#month_' + next).length > 0) {
				$('div.active').fadeOut('fast', function() {
					$(this).removeClass('active');
					$('div.ev_' + ev + '#month_' + next).fadeIn('fast').addClass('active');
				});
			}
		}
		
	});
	
	
	// CIKK KÜLDÉSE EMAILBEN
	
	$('div.article div.extras a.email').click(function() {
		$('div.popup div#form').show();
		$('div.popup div#response').hide();
		$('div.popup div#form input#to_name, div.popup div#form input#to_email, div.popup div#form textarea#message').attr('value', '');
		$('div.popup, div.faded').fadeIn('fast');
		$('div.faded').height($(document).height());
	});
	$('div.popup input.cancel, div.faded').click(function() { $('div.popup, div.faded').fadeOut('fast'); });
	
	$('div.popup form').submit(function() {
		jQuery.post($('input#ajaxurl').val(), { action: 'sendarticle', name: $('input#from_name').val(), email: $('input#from_email').val(), to_name: $('input#to_name').val(), to_email: $('input#to_email').val(), message: $('textarea#message').val(), title: $('input#article_title').val(), url: $('input#article_url').val() }, function(response) {
			if (response == 'siker') {
				$('div.popup div#form').fadeOut();
				$('div#response').addClass('success').html('Sikeresen elküldte a levelet!').fadeIn();
				var t = setTimeout(function() { $('div.faded').click(); }, 2000);
			} else {
				$('div#response').addClass('error').html('Hiba történt a küldés során. Kérjük próbálkozzon újra!').fadeIn();
			}
		});
		return false;
	});
	
	
	
	
	// MENÜ VÍZSZINTESSÉ TÉTELE
	
	var alap = $('ul.menu li.current-menu-item ul').html();
	if ($('li.current-menu-item').parent().hasClass('sub-menu')) alap = $('li.current-menu-item').parent().html();
	$('ul.submenucontainer').html(alap);
	
	$('ul.menu li').mouseover(function() {
		clearTimeout(t);
		if ($(this).children('ul').size() > 0) {
			$('ul.submenucontainer').html($(this).children('ul').html());
		} else
			$('ul.submenucontainer').html(alap);
	}).mouseout(function() {
		t = setTimeout(function() { $('ul.submenucontainer').html(alap); }, 7000); // 7 másodperc múlva visszaáll az eredeti menü
	});
	
	$('a.togglemenu').click(function() {
		$('ul.menu').slideToggle();
	});
	
	
	
	
	// EZT OLVASTA MÁR?
	if ($('div.ajanlo').length > 0)
		$(window).scroll(function() {
			var egyeb = $('div.egyeb').offset();
			var footer = $('div.footer').offset();
			if ((($(window).scrollTop() + $(window).height()) > (egyeb.top - 100)) && (($(window).scrollTop() + $(window).height()) < footer.top) && ($(window).scrollTop() > 150))
				$('div.ajanlo').slideDown();
			else
				$('div.ajanlo').slideUp();
		});
	
	
	
	
	
	// GALÉRIA BEÁLLÍTÁSOK
	
	$('body.kepgaleria div.gallery a.changepic').click(function() {
		
		var picid = $('a.bigpic img').attr('rel').replace(/kep_/g, '');
		if ($(this).hasClass('thumb')) picid = $(this).attr('rel').replace(/kep_/g, '');
		
		var irany = 'next';
		if ($(this).hasClass('prev')) irany = 'prev';
		if ($(this).hasClass('thumb')) irany = 'exact';
		
		$('a.bigpic img').remove();
		$('a.bigpic').html('').addClass('loading');
		
		jQuery.post($('input#ajaxurl').val(), { action: 'picchange', id : picid, pics : $('input#sorrend').val(), dir : irany, gid : $('input#gid').val()}, function(data) {
			var picture = jQuery.parseJSON(data);
			$('span.tags').html(picture.tags);
			$('span.picof').html(picture.picof);
			$('div.picdesc').html(picture.picdesc);
			$('a.bigpic').html(picture.src).removeClass('loading');
			$('ul.thumbs li.active').removeClass('active');
			$('ul.thumbs li#thumb_' + picture.picid).addClass('active');
		});
		
		//return false;
		
	});
	
	$('body.galeria a.embed').click(function() {
		$('textarea.embed').slideToggle('normal', function() { $('textarea.embed').focus().select(); });
		$(this).toggleClass('off');
	});
	
	if ($('body.kepgaleria').length != 0) {
		var picid = window.location.hash.replace(/kep_/g, '').replace(/#/g, '');
		
		if (picid != '') {
			$('a.bigpic img').remove();
			$('a.bigpic').html('').addClass('loading');
			
			jQuery.post($('input#ajaxurl').val(), { action: 'picchange', id : picid, pics : $('input#sorrend').val(), dir : 'exact', gid : $('input#gid').val()}, function(data) {
				var picture = jQuery.parseJSON(data);
				$('span.tags').html(picture.tags);
				$('span.picof').html(picture.picof);
				$('div.picdesc').html(picture.picdesc);
				$('a.bigpic').html(picture.src).removeClass('loading');
				$('ul.thumbs li.active').removeClass('active');
				$('ul.thumbs li#thumb_' + picture.picid).addClass('active');
			});
		}
	}
	
});
