function resizeContent() {
	$('#bar, #iBar').height($(window).height()-105);
	var diff = $('#content').height()-($(window).height()-105);
	if(0>diff) {
		$('#content').height($('#content').height()-diff);
	}
}

function resizeToggle() {
	if($(window).width()<1100) {
		$("link[alt='small']").attr('href','/_include/css/layoutSmall.css');
	} else {
		$("link[alt='small']").attr('href','');
	}
}

function startsite() {
	$('#iSlogan').delay(3000).show().delay(300).animate({width:'120px', top:'450px', left:'25px'}, 2000, function () {
		$('#iNavigation').fadeIn(400);
	});
}

function startsite_further() {
	$('#iSlogan').css({width:'120px', top:'400px', left:'10px'}).show();
	$('#iNavigation').fadeIn(600);
}

function imgGallery() {
	var innerContainer = $('#imgGalleryInnerContainer');
	var width = 0;
	$('img.imgGalleryImg').each( function() {
		width += $(this).width()+10;
	});
	innerContainer.width(width);

	$('#imgGalleryControlLeft').bind('click', function() {
		if(parseInt(innerContainer.css('margin-left'))<0) {
			innerContainer.animate({marginLeft:"+=90px"}, 500);
		}
	});

	$('#imgGalleryControlRight').bind('click', function() {
		ifMargin = width*-1+450;
		if(parseInt(innerContainer.css('margin-left'))>parseInt(ifMargin)) {
			innerContainer.animate({marginLeft:"-=90px"}, 500);
		}
	});
}

function disguiseSubNavigation(obj) {
	obj.find("a.subnavigation[title='-']").removeClass('subnavigation').addClass('subnavigation_blank').removeAttr('href');
	obj.find("a.mainNav02[title='-']").remove();
}

function isDefined(variable) {
	return eval('(typeof("'+variable+'") != "undefined");');
}

$(document).ready( function() {
	// PNG FIX für IE6
	$(document).pngFix();

	resizeToggle();
	
	// SIDEBAR RESIZE
	$(window).resize(function() {
		resizeContent();
	});
	
	// news slider auf startseite
	$("div.iNews:first").show();
	newsAnzahl = $("div.iNews").size();
	for(var i=0; i<newsAnzahl; i++) {
		num = i+1;
		$('#controller').append("<span rel='"+i+"'>"+num+"</span>");
		if(num != newsAnzahl) {
			$('#controller').append(" / ");
		}
	}

	$('#controller > span:eq(0)').css('font-weight',900);
	$('#controller > span').bind('click', function () {
		$('#controller > span').css('font-weight',500);
		$(this).css('font-weight',900);
		showID = $(this).attr('rel');
		$("div.iNews").hide();
		$("div.iNews:eq("+showID+")").show();
	});

	// leere bilder removen
	$("img[src='']").remove();
	
	//kein bild, kein DIV
	if(($('#small > img').size()==0 && $('#small').size()>0)) {
		$('#bild').remove();
		$('#topic').css('margin-top','25px');
	}
	
	//disguise SubNavigation
	if($('#subnavigation').size()>0) {
		disguiseSubNavigation($('#subnavigation'));
		disguiseSubNavigation($('#mainNav'));
	}
	
	// navi wahl "name" / "display"
	$('#mainNav a, #subnavigation a').each(function() {
		var e = $(this);
		if(e.find('span:eq(1)').text()=='') {
			e.find('span:eq(1)').remove();
		} else {
			e.find('span:eq(0)').remove();
		}
		
	});
	
	$("a[href$='.jpg'], a[href$='.jpeg'], a[href$='.gif'], a[href$='.png']").fancybox();
	
	//IMG ohne alt Text füllen
	$("img[alt='']").attr('alt','MAG, The Innovators in Magnet Wire');

	// tabelle übersichtlicher
	$('table.blaue-zeilen').each(function() {
		$(this).find('tr:odd').css('background-color','#f2f6f9');
	});

});

$(window).load(function () {
	if($('#imgGallery').size()>0) {
		imgGallery();
	}
	// bilderzoom
	picLarge = $("#large > img").attr('src');
	
	noPic = true;
	if(typeof(picLarge)!='undefined') {
		if($("#bild > div:visible").size()>1 || picLarge.length>5) {
			noPic = false;
			$('#bild').anythingZoomer({expansionSize: 30,speedMultiplier: 2.2});
			$('#zoomIn').show();
		}
	}
	if(noPic) {
		$("#overlay, #mover, #large, #small").css('cursor','auto');
	}
	
	if($('#small').size()>0) {
		picSmall = $('#small > img').attr('src');
		try {
			var lengthPicSmall = picSmall.length;
		} catch (e) {
			var lengthPicSmall = 5;
		}

		if((typeof(picSmall)!='undefined' && lengthPicSmall<2) || (typeof(picSmall)=='undefined' && lengthPicSmall>2)) {
			$('#bild').height(0).fadeTo(0.1,0.01);
			$('#zoomIn').hide();
		}
	}

	resizeContent();
});

$(window).resize(function() {
	resizeToggle();
});

