// JavaScript Document

$(document).ready (function ()
{
    // LEAD KEPEK LEMERETEZESE
    $("img.article-img").each (function ()
    {
        var pW = $(this).parent().parent().width();
        var pH = (pW * 100) / 220;
        $(this).parent().parent().height(pH);
        $(this).css ('width', pW);
    });
	
	$(".list-lead img").each (function ()
    {
		var imgW = $(this).width();
		var imgH = $(this).height();
		if ( imgW > 480 ) {
			var imgNWr = 480 / imgW;
			var imgNH = imgH * imgNWr;
			$(this).css('width', 480);
			$(this).css('height', imgNH);
		}
    });
	
	$('.blog-article .list-lead .list-lead-image img').each(function(){
		var thisSrc = $(this).attr('src') +'?'+ new Date().getTime();	
		$(this).attr('src', thisSrc);
	});
	
	$('.blog-article .list-lead .list-lead-image img').load(function(){
		var maxW = 276;
		var maxH = 125;
		var imgW = $(this).width();
		var imgH = $(this).height();
		$(this).css('max-width', '600px');
		if ( imgW >= imgH ) {
			$(this).animate({width: maxW}).parent().addClass('img-landscape');
		} else {
			$(this).animate({height: maxH}).parent().addClass('img-portrait');
		}
	});


    // MAIN LEAD HEIGHT
    //var maxLeadHeight = Math.max ($('#main-lead-left').height(), $('#main-lead-right').height())
    //$('#main-lead-right').height (maxLeadHeight);
    //$('#main-lead-left').height (maxLeadHeight);
	
	// KAPCSOLOD ANYAGOK MAGASSAGKIEGYENLITESE
	/*$('.rel-cont-item').each(function(){
		var relContH = 0;
		if ($(this).height() > relContH) {
			relContH = $(this).height();
		}
		$('.rel-cont-item').css("height", relContH);
	});*/
	
	// CIKK GALERIA
		
	$('.article-text img').each(function(){
		$(this).gallerizer();
	});
	$('.article-lead-image img').each(function(){
		$(this).gallerizer();
	});
	$('.img-uploaded').each(function(){
		$(this).gallerizer2();
	});
	
	$("a.article-gallery").fancybox({
            'titlePosition' 		: 'inside',
            'cyclic'				: true,
            'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
		    return  title + '&nbsp;<span style="float: right;">' +  (currentIndex + 1) + ' / ' + currentArray.length + '</span>';
		}
	});
	
	$("a.uploader-gallery").fancybox({
            'titlePosition' 		: 'inside',
            'cyclic'				: true,
            'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
		    return  title + '&nbsp;<span style="float: right;">' +  (currentIndex + 1) + ' / ' + currentArray.length + '</span>';
		}
	});


    // FEJL�C KERES�
    $('#navigation .search-wrapper .where a')
        .click (function ()
        {
            $('.search-wrapper a').removeClass ('active');
            $(this).addClass ('active');
            $('#searchTab').val (this.target);

            return false;
        });

    // GAL�RIA
    $('#article-gallery').galleryView (
        {
            show_captions: true,
            show_overlays: true,
            frame_width:   80,
            frame_height:  80,
            panel_width:   618
        });
		
	// RSS
	
	$('.toggle').click(function(e){
		var hrefA = $(this).attr('href');
		$(hrefA).slideToggle(400);
	});
	
	$('#rss-list').hover(function(){}, function(){
		$(this).slideToggle(400);
	});
	
});


	jQuery.fn.gallerizer = function(){
		var iframe = '';
		var siteBaseUrl = 'http://iho.hu/';
		var imgUrl = $(this).attr('src');
		var imgWidth = $(this).width();
		var imgAlt = $(this).attr('alt');
		var httpN = imgUrl.search(/http/i);
		if ( httpN < 0 ){
			imgUrl = siteBaseUrl + imgUrl;
		} else {
			if ( imgUrl.search(/iho/i) < 0) {
				iframe = 'iframe';
			}
		}
		
		$(this).wrap('<a href="'+imgUrl+'" rel="article-gallery" class="article-gallery '+iframe+'" style="width: '+imgWidth+'px;" title="'+imgAlt+'"></a>');
		if ( imgAlt.length > 0 ) {
			$(this).parent().append('<div class="image-caption"><img src="templates/images/icon_gallery_open_40_29.png" alt="view" class="view" />'+imgAlt+'</div>');
			$(this).attr('title', imgAlt);
		}
	}
	
	jQuery.fn.gallerizer2 = function(){
		var iframe = '';
		var siteBaseUrl = 'http://iho.hu/';
		var imgUrl = $(this).attr('src');
		var imgWidth = $(this).width();
		var imgAlt = $(this).attr('alt');
		var httpN = imgUrl.search(/http/i);
		if ( httpN < 0 ){
			imgUrl = siteBaseUrl + imgUrl;
		} else {
			if ( imgUrl.search(/iho/i) < 0) {
				iframe = 'iframe';
			}
		}
		
		$(this).wrap('<a href="'+imgUrl+'" rel="uploader-gallery" class="uploader-gallery '+iframe+'" style="width: '+imgWidth+'px;" title="'+imgAlt+'"></a>');
		if ( imgAlt.length > 0 ) {
			$(this).attr('title', imgAlt);
		}
	}

