// accordion
function initDropMenu(){
	var _slideSpeed = 400;
	$("ul.headline > li > strong > a").each(function() {
		$(this).click(function() {
			var _parent = $(this).parent().parent();
			var _slider = _parent.find("div").eq(0);
			var _collapseonly = false;

			if($(_parent).hasClass("expanded"))
				_collapseonly = true;
			else
				_collapseonly = false;

			// hide all lists on current level
			$(_parent).parent().find("> li.expanded").each(function(){
				var _openeditems = $(this).find("div");
				$(_openeditems).slideUp(_slideSpeed);
				$(_openeditems).parent().removeClass("expanded");
			});

			if(_parent.find("div").length > 0) {
				if($(_parent).hasClass("expanded")) {
					$(_slider).slideUp(_slideSpeed, function(){
						$(_parent).removeClass("expanded");
					});
				}
				else {
					if(!_collapseonly) {
						$(_slider).slideDown(_slideSpeed, function(){
							$(_parent).addClass("expanded")
						});
					}
				}
			}

			return false;
		});
	});
}

// logo rotation
function initLogoGallery() {
	$(document).ready(function() {
	    $('.header-rotator').cycle({
			fx: 'fade',
			timeout: 10000
		});
		$('.poster-area').cycle({
			fx: 'fade',
			timeout: 6000
		});
		$('.logos-area').cycle({
			fx: 'fade',
			timeout: 4000
		});
		
	});

}


// sliding gallery
function initSlideGallery() {
	var _slideSpeed = 450;

	$("div.slide-gallery").each(function(){
		var _galleryList = $(this).find("ul.gallery > li");
		var _galleryHolder = $(this).find("div.gallery-holder");

		var _toggleButton = $(this).find("a.toggler");
		var _galleryLength = _galleryList.length;
		var _itemHeight = $(_galleryList[0]).innerHeight(true)-14;
		var _listHeight = $(this).find("ul.gallery").outerHeight(true);

		if(_galleryLength > 4) {
			_galleryHolder.css({position:"relative",overflow:"hidden",height:_itemHeight});


			_toggleButton.click(function(){
				if(_toggleButton.hasClass("active")) {
					_galleryHolder.animate({height: _itemHeight}, _slideSpeed, false, function(){
						_toggleButton.removeClass("active");
					});
				}
				else {
					_galleryHolder.animate({height: _listHeight}, _slideSpeed, false, function(){
						//_galleryHolder.css("height","auto");
						_toggleButton.addClass("active");
					});
				}
				return false;
			});
		} else {
			_toggleButton.css("display","none");
		}
	});
}

// page init
function initPage(){
	initDropMenu();
	initLogoGallery();
	initSlideGallery();	
}

if (window.addEventListener) window.addEventListener("load", initPage, false);
else if (window.attachEvent) window.attachEvent("onload", initPage);



// JTnet Common JS Functions
function trim(sString){
		while (sString.substring(0,1) == ' '){
			sString = sString.substring(1, sString.length);
		}
		while (sString.substring(sString.length-1, sString.length) == ' '){
			sString = sString.substring(0,sString.length-1);
		}
		return sString;
		}

function clearText(thefield){
		if (thefield.defaultValue==thefield.value)
		thefield.value = ""
		} 
		
function checkForBlank(thefield){
		if (trim(thefield.value)=="")
		thefield.value = thefield.defaultValue
		}