
function initialize()
{
	iBox.initialize();

	styled_select.init();

	content_buttons.init();
	trends.init();
	
	service_promotion.init();
}
Element.observe( window, 'load', initialize, false );


var content_buttons = {

 init: function() {
 	var showButton = $('contentShowButton');
 	if( null!=showButton ) showButton.observe('click', content_buttons.__onShowClicked.bindAsEventListener(showButton) );
 	var hideButton = $('contentHideButton');
 	if( null!=hideButton ) hideButton.observe('click', content_buttons.__onHideClicked.bindAsEventListener(hideButton) );
 }
 
 ,__onShowClicked: function( ev ) {
 	var content = $('contentResults')
 	if( null!=content ) content.style.display = 'block';
 	var showButton = $('contentShowButton');
 	if( null!=showButton ) showButton.style.display = 'none';
 }
 ,__onHideClicked: function( ev ) {
 	var content = $('contentResults')
 	if( null!=content ) content.style.display = 'none';
 	var showButton = $('contentShowButton');
 	if( null!=showButton ) showButton.style.display = 'block';
 }
};

var trends = {
 visibleIndex: null
 ,trendCount: null

 ,init: function() {
 	var showContentButtons = $$('.trendShowStage');
 	for( var i=0; i < showContentButtons.length; i++ ) {
 		var button = showContentButtons[i];
 		button.observe('click', trends.__showContent.bindAsEventListener( button ) );
 	}
 	
 	var showProductsButtons = $$('.trendShowProducts');
 	for( var i=0; i < showProductsButtons.length; i++ ) {
 		var button = showProductsButtons[i];
 		button.observe('click', trends.__showProducts.bindAsEventListener( button ) );
 	}
 	
 	var srcTrends = $$('#allTrends .list a');
 	//var selectedTrend = $$('#allTrends .list .trend_selected');
 	//if( null!=selectedTrend ) selectedIndex = parseInt( selectedTrend.id.substr( 8 ) );
 	var visibleTrends = $$('#allTrends .box .body .trends a');
 	trends.trendCount = srcTrends.length;
 	if( !empty(srcTrends) && !empty(visibleTrends) ) {
 		var firstHref = visibleTrends[0].href;
 		for( var i=0; i < srcTrends.length; i++ ) if( srcTrends[i].href == firstHref ) {
 			trends.visibleIndex = parseInt( srcTrends[i].id.substr( 8 ) );
 			break;
 		}
 	}
 	if( trends.visibleIndex != null ) {
	 	var scrollLeftButton = $('trendsScrollLeft');
	 	if( null!=scrollLeftButton ) scrollLeftButton.observe('click', trends.__scrollLeft.bindAsEventListener( button ) );

	 	var scrollRightButton = $('trendsScrollRight');
	 	if( null!=scrollRightButton ) scrollRightButton.observe('click', trends.__scrollRight.bindAsEventListener( button ) );
	 }
 }
 
 ,showProducts: function() {
 	//var stage = $('trendStage');
 	//if( null!=stage ) stage.style.display = 'none';
 	//var details = $$('#trendProducts, #trendHeader, #trendFooter');
 	//for( var i=0; i < details.length; i++ ) details[i].style.display = 'block';
 	var url = DOM_getText( $('trendProductsUrl') );
 	if( !empty(url) ) {
 		window.location.href = url;
 	}
 }
 
 ,__showContent: function( ev ) {
 	//var stage = $('trendStage');
 	//if( null!=stage ) stage.style.display = '';
 	
 	//var details = $$('#trendProducts, #trendHeader, #trendFooter');
 	//for( var i=0; i < details.length; i++ ) details[i].style.display = 'none';
 	
 	//var header = $('header')
 	//if( null!=header ) header.scrollTo();
 	var url = DOM_getText( $('trendUrl') );
 	if( !empty(url) ) {
 		window.location.href = url;
 		ev.stop();
 		return false;
 	}
 }
 
 ,__showProducts: function( ev ) {
 	trends.showProducts();
 	ev.stop();
 	return false;
 }
 
 ,__scrollLeft: function( ev ) {
 	trends.visibleIndex = (trends.visibleIndex + trends.trendCount - 1) % trends.trendCount;
 	trends.__updateView();  
 }
 ,__scrollRight: function( ev ) {
 	trends.visibleIndex = (trends.visibleIndex + 1) % trends.trendCount;  
 	trends.__updateView();  
 }
 
 ,__updateView: function( ev ) {
 	var srcTrends = $$('#allTrends .list a');
 	var visibleTrends = $$('#allTrends .box .body .trends a');
 	var index = trends.visibleIndex;
 	for( var i=0; i < visibleTrends.length; i++ ) {
 		var dst = visibleTrends[ i ];
 		var src = srcTrends[ index ];
 		
 		dst.href = src.href;
 		dst.className = src.className;
 		dst.innerHTML = src.innerHTML;
 		
 		index = (index + 1) % trends.trendCount;
 	}	
 }  
 
};


var product_set_show = {
	init: function() {
	}
	
	,show: function( elem ) {
		
		var elems = elem.getElementsByTagName( 'div' );
			
		for(i=0;i<elems.length;i++) {			
			if ( elems[i].className == 'description' || elems[i].className == 'overlay' ) {				
				elems[i].style.display='block';
			}			
		}		 			
	}
	
	,hide: function( elem ) {
									
		var elems = elem.getElementsByTagName( 'div' );
			
		for(i=0;i<elems.length;i++) {			
			if ( elems[i].className == 'description' || elems[i].className == 'overlay' ) {					
					elems[i].style.display='none';
			}			
		}  		
	}
};

var service_promotion = {
	init: function() {
		var referrer = document.referrer;
		if( $('service_promotion') ) {
			var baseLocation = document.location.protocol + '//' + document.location.host;
			if( ''==referrer || 0!=referrer.indexOf(baseLocation) ) {
				$('service_promotion').show();
			}
		}
	}
};

