var c=c?c:{
	getContentId:function(el){
		return el.get("id")+"Content";
	},
	init:function(){
		var el=$("newsbox").getElement("h4");
		c.hide();
		el.addClass("active");
		c.show(el);
	},
	hide:function(){
		$$("#newsbox h4").each(function(el){
			$(c.getContentId(el)).addClass("hidden");
			el.removeClass("active");
		});
	},
	show:function(el){
		this.hide();
		el.addClass("active");
		$(c.getContentId(el)).removeClass("hidden");
	}
};

var n=n?n:{
	init:function(){
		$$("#navlist a").each(function(el){
			el.addEvent("mouseover", function(event){
				event.stop();
				n.show(this.get("id"));
			});
			el.addEvent("mouseout", function(event){
				event.stop();
				n.hide();
			});
		});
		$$(".subnav").each(function(el){
			el.addEvent("mouseover", function(event){
				event.stop();
				n.show(el.get("id").substr(0,el.get("id").lastIndexOf("Content")));
			});
			el.addEvent("mouseout", function(event){
				event.stop();
				n.hide();
			});
		});
		n.hide();
	},
	show:function(myId){
		n.hide();
		$(myId).addClass("active");
		var myCid=myId+"Content";
		if($(myCid)){
			var dim = $(myId).getCoordinates("col3");
			$(myCid).setPosition({x:dim.left,y:dim.bottom});
			$(myCid).removeClass("hidden");
		}
	},
	hide:function(){
		$$("#navlist a").each(function(el){
			el.removeClass("active");
		});
		$$(".subnav").each(function(el){
			el.addClass("hidden");
		});
	}
};

function sH(ar,x) {
	var mnH=mnS=0;
	var tA=[];
	ar.each(function(el,i){
		mnS = el.getStyle("paddingTop").toInt()+el.getStyle("paddingBottom").toInt()+el.getStyle("borderTopWidth").toInt()+el.getStyle("borderBottomWidth").toInt();
		if(mnH>0) {
			//if(tA[i-1]) alert("i: "+i+"\nel: "+el.getSize().y+"\ntA: "+tA[i-1].getSize().y);
			if(ar[i-1] && el.getSize().y > ar[i-1].getSize().y) mnH=el.getSize().y-mnS;
		}else{
			mnH=el.getSize().y-mnS;
		}
		tA.include(el);
		if(tA.length%x==0 || (i+1)==ar.length) {
			//alert(mnH);
			tA.each(function(ex){
				ex.setStyle("height", mnH);
			});
			mnH=0;
			tA.empty();
		}
	});
}
window.addEvent('domready', function(){
	if($("newsbox")) c.init();
	n.init();
	$$("#newsbox h4").each(function(el){
		el.addEvent("click", function(){
			c.show(el);
		});
	});

	/*Single Image*/
	if($("mainTopicBg")) {
		var dim = $("mainTopicText").getCoordinates();
		$("mainTopicBg").setStyles({display:"block", opacity:0.7, width:dim.width+"px", height:dim.height+"px"});
	}
	/* /Single Image */
	
	/* noob Slide */
	if (document.getElementById('mainStage')) {	
		if($("topicTextBg1")) {
			var dim1 = $("topicText1").getCoordinates();
			$("topicTextBg1").setStyles({display:"block", opacity:0.7, width:dim1.width+"px", height:dim1.height+"px"});
		}
		if($("topicTextBg2")) {
			var dim1 = $("topicText2").getCoordinates();
			$("topicTextBg2").setStyles({display:"block", opacity:0.7, width:dim1.width+"px", height:dim1.height+"px"});
		}
		if($("topicTextBg3")) {
			var dim1 = $("topicText3").getCoordinates();
			$("topicTextBg3").setStyles({display:"block", opacity:0.7, width:dim1.width+"px", height:dim1.height+"px"});
		}	

		//SAMPLE 2 (transition: Bounce.easeOut)
		var nS2 = new noobSlide({
			box: $('box2'),
			items: $$('#box2 span'),
			autoPlay: true,
			interval: 6000,
			size: 696,
			fxOptions: {
				duration: 1000,
				//transition: Fx.Transitions.Bounce.easeOut,
				transition: Fx.Transitions.easeOut,
				wait: false
			},
			addButtons: {
				previous: $('prev1'),
				/*play: $('play1'),
				stop: $('stop1'),*/
				next: $('next1')
			},
			handles: $$('#handles span'),
			onWalk: function(currentItem,currentHandle){
				this.handles.removeClass('active');
				currentHandle.addClass('active');
			}
		});
	}

	/* /noob Slide */

	var box = new multiBox('mb', {
		overlay: new overlay()
	});
	rating.init();
	var $i = 0;
	var lastObj = null;
/*
	$$(".boxnarrow").each(function(el){
		if($i%2==0) {
			lastObj = el;
		} else {
			mnHeight = (el.getStyle("height").toInt() > lastObj.getStyle("height").toInt())?el.getStyle("height"):lastObj.getStyle("height");
			el.setStyle("height", mnHeight);
			lastObj.setStyle("height", mnHeight);
		}
		$i++;
	});
*/
	sH($$(".teaserContainer .c33l p"),3);
	sH($$(".boxwide h3"), 1);
	sH($$(".boxwide .boxinfo h5"), 1);
	sH($$(".boxnarrow h3"), 2);
	sH($$(".boxnarrow .boxinfo h5"), 2);
	sH($$(".boxnarrow .boxinfo p"), 2);
	sH($$(".boxnarrow .boximg"), 2);
	sH($$(".boxnarrow .boxtext:not(.boxlist)"), 2);
	sH($$(".boxnarrow"), 2);
		
});

function tipafriend(){
	a2a_menu_type="mail";
	a2a_onMouseOver_stay();
}

function resetDealersearch(input) {
	input.value="";
}

function dump(myvar)
{
	var dump="";
	for (i in myvar) dump += i+": "+myvar[i]+"<br/>\n";
	alert(dump);
//	return dump;
}

