function gotosite(filter,selection,liga){
	if(filter != "blank" )location.href= ('/schedules.asp?liga='+liga+'&filter='+filter+'&selection='+selection);
};

function checkEMail(fieldName){
	var x= fieldName.value;
	var filter= /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if(filter.test(x))return true;
	else return false;
};

var ico, icoTitle, expandedNews= false, expandedLigaBox= false, $clonedDiv, standingsShown=new Array;
function expandBox(sec,elmid,orientationUpDwn,orientationLR){
	var getCoordsDims= function(el){
		return {
			'top':$jq(el).position().top+'px',
			'left':$jq(el).position().left+'px',
			'width':$jq(el).width()+'px',
			'height':$jq(el).height()+'px',
			'margintop':$jq(el).css('margin-top'),
			'marginright':$jq(el).css('margin-right'),
			'marginbottom':$jq(el).css('margin-bottom'),
			'marginleft':$jq(el).css('margin-left'),
			'paddingtop':$jq(el).css('padding-top'),
			'paddingright':$jq(el).css('padding-right'),
			'paddingbottom':$jq(el).css('padding-bottom'),
			'paddingleft':$jq(el).css('padding-left'),
			'float':$jq(el).css('float')
		};
	};
	var animateDiv= function(isBoxExpanded){
		if(isBoxExpanded){
			// get the positions of the original element, so that we can place it with position:absolute to the exact same position:
			origCoordsDims= getCoordsDims($jq('#'+elmid));
			// position the original element absolutely and with a high z-index, making it possible to lay it over all other elements:
			$jq('#'+elmid).css({'position':'absolute','top':origCoordsDims.top,'left':origCoordsDims.left,'z-index':'1000'});
			// clone the original element to act as a placeholder, keeping the floated layout intact,
			// and place it right before the original element,
			// and append '_cloned' to the id:
			$clonedDiv= $jq('#'+elmid).clone().attr('id',elmid+'_cloned');
			$clonedDiv.insertBefore($jq('#'+elmid)).css({'position':'relative','top':'0','left':'0','float':origCoordsDims.float,'width':origCoordsDims.width,'height':origCoordsDims.height,'margin-top':origCoordsDims.margintop,'margin-right':origCoordsDims.marginright,'margin-bottom':origCoordsDims.marginbottom,'margin-left':origCoordsDims.marginleft,'padding-top':origCoordsDims.paddingtop,'padding-right':origCoordsDims.paddingright,'padding-bottom':origCoordsDims.paddingbottom,'padding-left':origCoordsDims.paddingleft});
			//give the orig element a distinctive shadow:
			$jq('#'+elmid).css({'-webkit-box-shadow':'0 0 30px 2px #000','-moz-box-shadow':'0 0 30px 2px #000','box-shadow':'0 0 30px 2px #000'});
		};
		// animate the original element:
		$jq('#'+elmid).animate({'height': '+='+heightenBy+'px','width': '+='+widenBy+'px','left':'-='+moveLeftBy+'px','top':'-='+moveTopBy+'px'}, 'normal', function(){
			$jq('#'+elmid+' .'+icoClass).attr({'src':ico,'alt':icoTitle,'title':icoTitle});
			$jq('#'+elmid+' .'+icoClass).parent('a').attr({'title':icoTitle});
			// add a special class to prevent active element's icon to be hidden:
			$jq('#'+elmid+' .'+icoClass).removeClass(icoClass).addClass(icoClassActive);
			// hide all other icons:
			$jq('img.'+icoClass).fadeOut('slow');
			$jq('img.'+icoClassActive).show();
			$jq('#'+elmid+' .standings').show();
			
			if(!isBoxExpanded){
				// hide the standings first:
				$jq('#'+elmid+' .standings').hide();
				// set the position of the original element back to 'relative':
				$jq('#'+elmid).css({'position':'relative','top':'0','left':'0','-webkit-box-shadow':'none','-moz-box-shadow':'none','box-shadow':'none','z-index':'1'});
				// and remove the cloned element 
				$clonedDiv.remove();
				$jq('#'+elmid+' .'+icoClassActive).removeClass(icoClassActive).addClass(icoClass);
				$jq('img.'+icoClass).fadeIn('slow');
				$jq('#'+elmid+' .'+icoClass).attr({'src':ico,'alt':icoTitle,'title':icoTitle});
			};
		});
	};
	var showStandings= function(liga){
		if($jq.inArray(liga,standingsShown)==-1){
			$jq.getJSON(
				'/inc/standings_json.asp', {'liga':liga},
				function(data){
					$jq('#'+elmid+' .standings .overview').empty();
					$jq('#standingsTemplate').tmpl(data).appendTo($jq('#'+elmid+' .standings .overview'));
					$jq('#'+elmid+' .standings').tinyscrollbar_update();
					standingsShown.push(liga);
				}
			);
		};
	};
	
	
	icoClass= 'butMore';
	icoClassActive= 'butMoreActive';
	if(sec=='news'){
		if(!expandedNews){
			heightenBy= $jq('#newsList').height() + $jq('#newsList').position().top - $jq('#'+elmid).height();
			widenBy= 0;
			moveLeftBy= 0;
			moveTopBy= 0;
			expandedNews= true;
			ico= '/img/ico_minus.png';
			icoTitle= 'weniger...';
		} else {
			heightenBy= -heightenBy;
			widenBy= -widenBy;
			moveLeftBy= -moveLeftBy;
			moveTopBy= -moveTopBy;
			expandedNews= false;
			ico= '/img/ico_plus.png';
			icoTitle= 'mehr...';
		};
		animateDiv(expandedNews);
		
	} else if(sec=='liga'){
		if(!expandedLigaBox){
			heightenBy= $jq('#'+elmid).outerHeight() + parseFloat($jq('#'+elmid).css('margin-top')) + parseFloat($jq('#'+elmid).css('margin-bottom'))
			widenBy= $jq('#'+elmid).outerWidth() + parseFloat($jq('#'+elmid).css('margin-left')) + parseFloat($jq('#'+elmid).css('margin-right'));
			moveLeftBy= orientationLR=='l' ? $jq('#'+elmid).outerWidth() + parseFloat($jq('#'+elmid).css('margin-left')) + parseFloat($jq('#'+elmid).css('margin-right')) : 0;
			moveTopBy= orientationUpDwn=='up' ? $jq('#'+elmid).outerHeight() + parseFloat($jq('#'+elmid).css('margin-top')) + parseFloat($jq('#'+elmid).css('margin-bottom')) : 0;
			expandedLigaBox= true;
			ico= '/img/ico_close.png';
			icoTitle= 'weniger...';
			
			showStandings($jq('#'+elmid).children('div').attr('class').split(' ').slice(-1).toString());
		} else {
			heightenBy= -heightenBy;
			widenBy= -widenBy;
			moveLeftBy= -moveLeftBy;
			moveTopBy= -moveTopBy;
			expandedLigaBox= false;
			ico= '/img/pic_arr_'+orientationUpDwn+'_'+orientationLR+'.png';
			icoTitle= 'mehr...';
		};
		animateDiv(expandedLigaBox);
	};
};
function placeArrows(divCollection, containerWidth, containerHeight){
	$jq(divCollection).each(function(){
		icoClass= 'pos';
		
		lr= $jq(this).position().left>containerWidth/2 ? 'l' : 'r';
		updwn= $jq(this).position().top>containerHeight/2 ? 'up' : 'dwn';
		
		ico= '/img/pic_arr_'+updwn+'_'+lr+'.png';
		icoClass+= lr=='l' ? 'Left' : 'Right';
		icoClass+= updwn=='up' ? 'Up' : 'Down';
		
		$jq(this).append('<img class="butMore '+icoClass+'" src="'+ico+'" width="24" height="24" alt="mehr..." title="mehr...">');
		$jq(this).find('img.butMore').bind(
			'click',
			{elmid: $jq(this).attr('id'),updwn:updwn,lr:lr},
			function(event){
				expandBox('liga',event.data.elmid,event.data.updwn,event.data.lr);
			}
		);
	});
};
