$(document).ready(function(){
	
	$(this).initBody(); // body classes
	$(this).formInit(); // append class depending on type of input
	$(this).firstLastChild(); // appends class to first and list children of lists, td and th elements
//	$(this).evenOddChild(); // appends class to odd and even list children of lists, td and th elements
//	$(this).brokenImage(); // hides broken images
	
	//$(this).markExtLink('out'); // marks external links : options 'in' or 'out' depending where tha marker has to be related to the link
	
	
/////////////////////////////////////////////////////////
//            FIRST ITEM
////////////////////////////////////////////////////////

$('#header-nav li:first-child, #navigation li:first-child, #footer-nav li:first-child').addClass('first');
$('#header-nav li:last-child, #navigation li:last-child, #footer-nav li:last-child').addClass('last');

/////////////////////////////////////////////////////////
//            DROPDOWN
////////////////////////////////////////////////////////
	
	$("ul#navigation > li").hover(function(){
    
        $(this).addClass("hover");
        //$('ul:first',this).slideDown(400);
		$('ul:first',this).css('display', 'block');
    
    }, function(){
    
        $(this).removeClass("hover");
        //$('ul:first',this).slideUp(400);
    	$('ul:first',this).css('display', 'none');
    });
	
/////////////////////////////////////////////////////////
//            SLIDE INIT
////////////////////////////////////////////////////////

	$('#slider').each(function(){
		$('#slider').anythingSlider({
			'autoPlay' : true,
			'onInitialized' : function(){
				$('.anythingSlider').append('<div class="control-background">');
			}
		});
	});
	
/////////////////////////////////////////////////////////
//            FANCYBOX
////////////////////////////////////////////////////////
    
    function formatTitle(title, currentArray, currentIndex) {
        return '<div class="fancybox-title-padding">' + title + '' + ' (' + (currentIndex + 1) + '/' + currentArray.length + ') </div>';
    }
    
    $('.view-picture').fancybox({
        'padding'        : 0,
        'titlePosition'    : 'inside',
        'titleFormat'    : formatTitle,
		'onComplete'	: function(){$('#fancybox-outer').addClass('image-box');}
    });
    
    $('.nls').fancybox({
        'padding'        : 0,
		'width'			: 311,
		'height'		: 171
    });
	


	
/////////////////////////////////////////////////////////
//            HONAP EMBERE EVES BONTAS
////////////////////////////////////////////////////////
	
	$('.year-wrapper ul').hide();
	$('.toggle-next-tab').click(function(){
		$(this).next('ul').slideToggle(500);
		return false;
	});

/////////////////////////////////////////////////////////
//            JCAROUSEL
////////////////////////////////////////////////////////

	$('.carousel').jcarousel({itemFallbackDimension: 300});
	
	
/////////////////////////////////////////////////////////
//            TEASER IMAGE
////////////////////////////////////////////////////////


	$('.teaser-image img').load(function(){
		var tImgH = $(this).height();
		var tImgW = $(this).width();
		if (tImgH == tImgW) {
			$(this).removeClass('no-resize');
			$(this).addClass('img-square');
		} else
		if (tImgH > tImgW) {
			$(this).removeClass('no-resize');
			$(this).addClass('img-landscape');
			if ( (180 / tImgH * tImgW) < 140 ) {
				var scale = 140 / tImgW * tImgH;
				$(this).css('width', 'auto');
				$(this).css('height', scale);
				$(this).removeClass('img-landscape');
			} else {
				$(this).addClass('img-landscape');
			}
		} else {
			$(this).removeClass('no-resize');
			$(this).addClass('img-portrait');
			if ( (140 / tImgW * tImgH) < 180 ) {
				var scale = 180 / tImgH * tImgW;
				$(this).css('height', 'auto');
				$(this).css('width', scale);
				$(this).removeClass('img-portrait');
			} else {
				$(this).addClass('img-portrait');
			}

		}
	});

	$('.small-thumb-img').load(function(){
		var tImgH = $(this).height();
		var tImgW = $(this).width();
		if (tImgH > tImgW) {
			$(this).removeClass('no-resize');
			$(this).addClass('img-landscape');
			if ( (110 / tImgH * tImgW) < 100 ) {
				var scale = 100 / tImgW * tImgH;
				$(this).css('width', 'auto');
				$(this).css('height', scale);
				$(this).removeClass('img-landscape');
				$(this).removeClass('no-resize');
			} else {
				
			}
		} else {
			$(this).removeClass('no-resize');
			$(this).addClass('img-portrait');
			if ( (100 / tImgW * tImgH) < 110 ) {
				var scale = 110 / tImgH * tImgW;
				$(this).css('height', 'auto');
				$(this).css('width', scale);
				$(this).removeClass('img-portrait');
			} else {
				
			}

		}
	});
	
	$('.gallery-image img').load(function(){
		var tImgH = $(this).height();
		var tImgW = $(this).width();
		if (tImgH > tImgW) {
			$(this).addClass('img-landscape');
			if ( (140 / tImgH * tImgW) < 140 ) {
				var scale = 140 / tImgW * tImgH;
				$(this).css('width', 'auto');
				$(this).css('height', scale);
				$(this).removeClass('img-landscape');
			} else {
				$(this).addClass('img-landscape');
			}
		} else {
			$(this).addClass('img-portrait');
			if ( (140 / tImgW * tImgH) < 140 ) {
				var scale = 140 / tImgH * tImgW;
				$(this).css('height', 'auto');
				$(this).css('width', scale);
				$(this).removeClass('img-portrait');
			} else {
				$(this).addClass('img-portrait');
			}

		}
	});
	
	
if($.browser.msie && parseInt($.browser.version, 10) <= 9) {
	resizer();
    setTimeout("resizer()", 3000);
}

});

function resizer(){
	
	$('.teaser-image img').each(function(){
		
	
		var tImgH = $(this).height();
		var tImgW = $(this).width();
		if (tImgH == tImgW) {
			$(this).removeClass('no-resize');
			$(this).addClass('img-square');
		} else
		if (tImgH > tImgW) {
			$(this).removeClass('no-resize');
			$(this).addClass('img-landscape');
			if ( (180 / tImgH * tImgW) < 140 ) {
				var scale = 140 / tImgW * tImgH;
				$(this).css('width', 'auto');
				$(this).css('height', scale);
				$(this).removeClass('img-landscape');
			} else {
				$(this).addClass('img-landscape');
			}
		} else {
			$(this).removeClass('no-resize');
			$(this).addClass('img-portrait');
			if ( (140 / tImgW * tImgH) < 180 ) {
				var scale = 180 / tImgH * tImgW;
				$(this).css('height', 'auto');
				$(this).css('width', scale);
				$(this).removeClass('img-portrait');
			} else {
				$(this).addClass('img-portrait');
			}

		}
	});
	
	
	$('.small-thumb-img').each(function(){

		var tImgH = $(this).height();
		var tImgW = $(this).width();
		if (tImgH > tImgW) {
			$(this).removeClass('no-resize');
			$(this).addClass('img-landscape');
			if ( (110 / tImgH * tImgW) < 100 ) {
				var scale = 100 / tImgW * tImgH;
				$(this).css('width', 'auto');
				$(this).css('height', scale);
				$(this).removeClass('img-landscape');
			} else {
				
			}
		} else {
			$(this).removeClass('no-resize');
			$(this).addClass('img-portrait');
			if ( (100 / tImgW * tImgH) < 110 ) {
				var scale = 110 / tImgH * tImgW;
				$(this).css('height', 'auto');
				$(this).css('width', scale);
				$(this).removeClass('img-portrait');
			} else {
				
			}

		}
	});
	
	$('.gallery-image img').each(function(){
		var tImgH = $(this).height();
		var tImgW = $(this).width();
		if (tImgH > tImgW) {
			$(this).addClass('img-landscape');
			if ( (140 / tImgH * tImgW) < 140 ) {
				var scale = 140 / tImgW * tImgH;
				$(this).css('width', 'auto');
				$(this).css('height', scale);
				$(this).removeClass('img-landscape');
			} else {
				$(this).addClass('img-landscape');
			}
		} else {
			$(this).addClass('img-portrait');
			if ( (140 / tImgW * tImgH) < 140 ) {
				var scale = 140 / tImgH * tImgW;
				$(this).css('height', 'auto');
				$(this).css('width', scale);
				$(this).removeClass('img-portrait');
			} else {
				$(this).addClass('img-portrait');
			}

		}
	});
	
}

