var categoriShow 					= 0 ; 
var TEXT_SMOOTH_ROLLOVER_TIME       = 250 ;            
var TEXT_SMOOTH_ROLLOVER_COLOR      = '#F26938' ;      
var IMAGE_SMOOTH_ROLLOVER_TIME      = 400 ;         
var SIMPLE_TIP_SHOWTIME             = 300 ;          
var IMAGE_SMOOTH_ROLLOVER           = IMAGE_SMOOTH_ROLLOVER_TIME > 0 ? true : false ;
var TEXT_SMOOTH_ROLLOVER            = TEXT_SMOOTH_ROLLOVER_TIME  > 0 ? true : false ;
var OVER_KEYWORD                    = '_over';
var OVER_LINK_ACTION                = true ;
var OVER_LINK_ROLLOVER              = true ;
    OVER_LINK_ROLLOVER              = OVER_LINK_ROLLOVER &&  OVER_LINK_ROLLOVER ? true : false ;
var ACTIVE_KEYWORD					= '_active'; // false ;
var DISABLED_KEYWORD				= '_disabled'; // false ;
//** CDN **//
var CDN_URL = 'http://i.cdn.turner.com/toonla/images/boomix/assets/site' ;
//** CDN **//

// ---------------------------------------------------------------------------------------------------------- >
 

window.alert =  function (text , title) {

	if ( text ) {
		if ( !is_image(text)  ) {
			try {
				StickyWin.alert( (title || 'Boomix' ) , text , CDN_URL + '/design/assets/img/common' );
			} catch (e) {
				window.parent.StickyWin.alert((title || 'Boomix' ), text , CDN_URL + '/design/assets/img/common' );
			}
		} else {
			new StickyWinModal({
			  content: '<img class="closeSticky" src="'+text+'" width="300" height="200" />',
			  position: 'center',
			  modalOptions: {
				modalStyle:{
				  'background-color':'#C4252E',
				  'opacity':.6
				}
			  }
			}).show()		
		}
	}	
}

function is_image( sText ) {
	return String(sText).match(/(\.jpg|\.gif|\.png|\.jpge)$/g);
}


function toggleImageActive (e) {
    e.toggleClass('active');
    imageDoRollOver(e  , e.hasClass('active') ) ;
}

// SCROLL //-------------------------------------------------------------------------------------------------------------------------------
function makeScrollbar(content,scrollbar,handle,horizontal,ignoreMouse){
    var axis = horizontal ? 'x' : 'y'  ;
	
	oldC = content.getStyle('display');
   	oldS = scrollbar.getStyle('display');
	oldK = handle.getStyle('display');
	
	content.setStyle('display','block');
	scrollbar.setStyle('display','block');
	handle.setStyle('display','block');
	
	a1 = content.getSize() ;
    a2 = content.getScrollSize() ;
    
	if ( a1[axis] >= a2[axis] ) {
        scrollbar.setStyle('display' , 'none' ) ;
		
	} else {
        var steps = (horizontal?(content.getScrollSize().x - content.getSize().x):( content.getScrollSize().y - content.getSize().y));
        var steps = steps == 0 ? 100 : steps;
        var slider = new Slider( scrollbar , handle , {   
            steps: steps,
            mode: (horizontal?'horizontal':'vertical'),
            onChange: function(step){
                var x = (horizontal?step:0);
                var y = (horizontal?0:step);
                content.scrollTo ( x , y );
            }
        }).set(0);

        if( !(ignoreMouse) ){
            $$(content, scrollbar).addEvent('mousewheel', function(e){ 
                e = new Event(e).stop();
                var step = slider.step - e.wheel * 30; 
                slider.set(step);               
            });
        }
        $(document.body).addEvent('mouseleave',function(){slider.drag.stop()});
		content.setStyle('overflow' , 'hidden') ;
		content.setStyle('display',oldC);
		scrollbar.setStyle('display',oldS);
		handle.setStyle('display',oldK);
    }

}
// SCROLL //-------------------------------------------------------------------------------------------------------------------------------



function overTween ( e , nColor , oColor ) {
    oColor = oColor ? oColor : e.getStyle('color') ; 
    nColor = nColor ? nColor : TEXT_SMOOTH_ROLLOVER_COLOR ;   
    e.set('tween', {duration: TEXT_SMOOTH_ROLLOVER_TIME });
    e.set('oColor', oColor ) ; 
    e.set('nColor', nColor ) ; 
    
    
    e.addEvent('mouseover', function (){
        if (TEXT_SMOOTH_ROLLOVER) {
            this.tween('color', this.get('nColor') );     
        } else {
            this.set('color', this.get('nColor') );   
        }      
    });
    
    e.addEvent('mouseout', function (){
        if ( !this.hasClass('active')) {
            if (TEXT_SMOOTH_ROLLOVER) {
                this.tween('color', this.get('oColor') );
            } else {
                this.set('color', this.get('oColor') );  
            }
        } else {
            if (TEXT_SMOOTH_ROLLOVER) {
                this.tween('color', this.get('nColor') );
            } else {
                this.set('color', this.get('nColor') );    
            }
        }
          
        
    });   
}


function toolTip() {
    myWin.hide();
}


function imageDoRollOver( e , status ) {
	if ( !(status) ){
		if (IMAGE_SMOOTH_ROLLOVER){
			e.tween('opacity' , 1 );
		} else {
			e.set('src' , e.retrieve('originalSRC') ) ;
		}
	} else {
		if (IMAGE_SMOOTH_ROLLOVER){
			e.tween('opacity' , 0.00001 );
		} else {
			e.set('src' , e.retrieve('overSRC') ) ;
		}
	}
}


function imgRollOver (e) {
 if (String(e.retrieve('originalSRC')) == 'null' ){
	var src = e.src ;

	src = src.split('/');
	image = src[src.length-1] ;
	image = image.split('.');
	src = e.src ;
	if ( src ) {
	src = src.replace( image[0] , image[0] + OVER_KEYWORD  );
	src = src.replace( '_active' , ''  );
	
	e.setStyle('cursor' , 'pointer') ;    
	e.store('overSRC', src );  
	e.store('originalSRC' , e.src ) ;
	
	if (!IMAGE_SMOOTH_ROLLOVER) { 
		e.setStyle('float', 'left') ; 
		e.setStyle('display', 'block') ; 
		if (window.ie){
			e.setStyle('margin-left', -3) ; 
			e.setStyle('margin-right', -3) ; 
		}
	} else { 
		e.set('tween', {duration: IMAGE_SMOOTH_ROLLOVER_TIME });
		w = e.getStyle('width'); 
		e.setStyle('display', 'none') ; 
		var div = new Element('div') ;
		div.setStyle('display', 'none') ; 
		div.setStyle('background' , 'url('+ src +') top left no-repeat'); 
		div.setStyle('float', 'left') ; 
		div.setStyle('width', w) ; 
		div.inject(e , 'before' ) ; 
		div.grab(e);
		div.setStyle('display', 'block') ; 
		e.setStyle('display', 'block') ; 
	}

	if ( !e.hasClass('votes') ) { imageDoRollOver( e  , e.hasClass('active')  ) } ;
	
	e.addEvent('mouseenter', function (){
	  imageDoRollOver( this  ,true ) ;
	});
	
	e.addEvent('mouseleave', function (){
		imageDoRollOver( this ) ;
	});

	a = e.getParent('a');
	if (a && OVER_LINK_ACTION ){
		if ( a.href ) {
		
			// this add over to link if innerText != '' 
			if ( a.innerText != '' ) {
				a.addEvent('mouseenter', function (){
					el = this.getElement('img.rollOver') ;
					if ( el ){
						imageDoRollOver( el , true ) ;
						if (e.alt) {
							var content = e.get('alt').split('::') ;  
							e.store('tip:title', content[0]);  
							e.store('tip:text', content[1]);  
						}
					}
				});
				
				a.addEvent('mouseleave', function (){
					el = this.getElement('img.rollOver') ;
					if ( el ){
						imageDoRollOver( el ) ;
					}
				});
			}
			
			// toolTips . {esto no tendria que estar aca. pero por cuestiones de tiempo ...}
			if ( String(a.get('title')) != 'null' && OVER_LINK_ROLLOVER ) {
				text = String(a.get('title')).split('::') ;
				$(a).store('tip:title' , text[0] );
				$(a).store('tip:text'  , text[1] );
				var SimpleTip = new Tips( a , { showDelay: SIMPLE_TIP_SHOWTIME , hideDelay: 50, offsets: {x: -50, y: 41}, fixed: false });
			}
		 
			if ( a.href != '' &&  !(String(a.href).match("#") == '#' )) {                    
				if (IMAGE_SMOOTH_ROLLOVER) { 
					div.addEvent('click', function (){
						a = this.getParent('a');
						manageLink (a);
						return false ;
					});
				} else {
					e.addEvent('click', function (){
						a = this.getParent('a');
						manageLink (a)
						return false ;
					});
				}
			}
			
			
		}
	}
}	
}
}
	

function manageLink (a) {
 
	if ( a.target && a.target != '_SELF' ) { 	
		window.open(a.href , a.target)
	} else {
		document.location = a.href;
	}
}	

function lightBoxAjax ( URL ) {
	if ( $('bkg_opaque') ) {
		//$('bkg_opaque').dispose();
		iframe = $('lightBoxCtnr');
		iframe.allowTransparency  = true ;
		iframe.height= 1 ;
		iframe.setStyle('height' , '1px') ;
		iframe.src = URL;
	} else {

		var bkg_opaque = new Element('div' , { id : 'bkg_opaque' });
	
		div = new Element('div').setStyles({ 
			'margin-left' : 'auto' ,
			'margin-right' : 'auto' ,
			'width' : 960
		});
	
		iframe = new Element('iframe' , { 
			id: 'lightBoxCtnr' ,
			scrolling:'no' ,
			allowtransparency:true ,
			frameborder:'0' ,
			marginheight:'0' ,
			marginwidth:'0' ,
			width:'100%', 
			style:'background-color:transparent' ,
			height: 400
		}).inject(div);
	
		div.inject(bkg_opaque);
	
		bkg_opaque.inject('main' , 'before');
	
		iframe.allowTransparency  = true ;
		iframe.height= 1 ;
		iframe.setStyle('height' , '1px') ;
		//iframe.src =  URL  ;
		iframe.src = URL;
	}


}

function fixIframeSize() {
	try { bkg_opaque = $('bkg_opaque') || window.parent.$('bkg_opaque') } catch (e) {}
	bkg_opaque.setStyle('display' , 'block');
	var size = window.getSize();
	e = $('lightBoxCtnr') || iframe ;
	

	var oDoc =  e.contentWindow || e.contentDocument;
	if (oDoc.document) {
		oDoc = oDoc.document;
	}			
	
	targetHeight = ( oDoc.getScrollSize() ) ? (size.y <= oDoc.getScrollSize().y ? oDoc.getScrollSize().y :size.y  ) : size.y  ; 
	targetHeight = ( window.getScrollSize().y > targetHeight ) ?   window.getScrollSize().y :  targetHeight; 
	
	
	bkg_opaque.setStyles({
		'display' : 'block',
		'height': targetHeight  + 'px'
	});
	
	iframe.height= targetHeight + 'px' ; 
	e.setStyle('height', targetHeight + 'px') ; 
	window.scrollTo(0, 0);
	//bkg_opaque.fade('hide');
	//bkg_opaque.fade('in');
	bkg_opaque.setStyle('display','block');	
}


var saved = true ;


window.addEvent('domready', function() {
  	

	if ( $$('.bkg_splashpage').length  >= 1 ) {
		if ( Browser.Engine.trident  ) {
			if ( Browser.Engine.version <= 4 ) {
				alert(
						"<span style='font-size : 10px ; font-weight : normal'>" +
						"Boomerang y Boomix requieren Internet Explorer 7 o superior. Si tu equipo utiliza una versión anterior, por favor actualízalo gratuitamente haciendo <a href='link: http://www.microsoft.com/spain/windows/internet-explorer/download-ie.aspx'>click aquí</a><br /><br />" + 
						"O site do Boomerang e o Boomix requerem Internet Explorer 7 ou superior. Se seu computador utiliza uma versão anterior, atualize-o gratuitamente <a href='link: http://www.microsoft.com/latam/windows/internet-explorer/'>clicando aqui</a><br /><br />" + 
						"Boomerang and Boomix require Internet Explorer 7 or newer. If your computer uses an older version than that please update it by  for your free download. <a href='link: http://www.microsoft.com/windows/internet-explorer/default.aspx'>clicking here</a><br /><br />"
						+ "</span>" 
					);
			}
			
		}
	}
	



 	function getConfirmMsg() {
		return 'Existe informacion sin guardar!';
	}

	function status( bStatus ){
		saved = bStatus ; 
	}

	function isAllSaved(){
		return saved;
	}	

	window.onbeforeunload = function() {
		if (!isAllSaved()) {
			return getConfirmMsg();
		} else {
			return ;
		}
	}
	
	Rolls = $$('.rollOver');
	Rolls.each(function(e){ imgRollOver (e) });
	
	
	$$('.votes').each( function (e){
			e.set('tween' , { link : 'cancel'} );
			var src = e.src ;
			src = src.split('/');
			image = src[src.length-1] ;
			image = image.split('.');
			e.store('disabledSRC', e.src.replace( image[0] , image[0] + DISABLED_KEYWORD  ) );  
			e.store('overSRC', e.src.replace( image[0] , image[0] + OVER_KEYWORD  ) );  
			e.store('activeSRC', e.src.replace( image[0] , image[0] + ACTIVE_KEYWORD  ) );  
			e.store('originalSRC' , e.src ) ;
		
			if( e.hasClass('disabled') ){
				e.set('src' , e.retrieve('disabledSRC') ) ;
				e.setStyle('float' ,'left' ) ;
			} else {
				e.addEvent('mouseenter', function (){
						elements = this.retrieve('parents') ;
						
						if ( String(elements) == 'null' ) { 
							elements = this.getParent('div');
							elements = elements.getParent('a');
							elements = elements.getParent('div');
							elements = elements.getAllPrevious('div') ;
							e.store('parents', elements );  
						}
						
						
 
						elements.reverse().each(function(e){
							img = e.retrieve('target_img') ;
							if ( String(img) == 'null' ) { 
								e = e.getFirst('a');
								e = e.getFirst('div')
								img =e.getFirst();
								e.store('target_img', img );  
							}
							 
							if ( img )
								imageDoRollOver( img , true);						 
						});
						imageDoRollOver( this  ,true ) ;
				});

				
				e.addEvent('mouseleave', function (){
						elements = this.retrieve('parents') ;
						if ( String(elements) == 'null' ) { 
							elements = this.getParent('div');
							elements = elements.getParent('a');
							elements = elements.getParent('div');
							elements = elements.getAllPrevious('div') ;
							e.store('parents', elements );  
						}
						
						imageDoRollOver( this  ,false ) ;
						elements.each(function(e){
							img = e.retrieve('target_img') ;
							if ( String(img) == 'null' ) { 
								e = e.getFirst('a');
								e = e.getFirst('div')
								img =e.getFirst();
								e.store('target_img', img );  
							}
							imageDoRollOver( img , false);
						});
				});

				if( e.hasClass('active') ){ 
					e.set('src' , e.retrieve('activeSRC') ) ;
				}
			}
		});
	

    $$('.footer a').each ( function (e) { overTween(e) ; }) ;
    
	$$('.popUp').each(function(e){ 
		e.set('oldHref' , e.get('href') ) ;
		e.set('href' , '#') ; 
		e.addEvent('click' ,function(){
			lightBoxAjax(this.get('oldHref'));
			return false ;
		});
	});


	$$('img.ttips').each( function(e) {
		text = String(e.get('alt'));
		if ( text != '' ) {
			var eTitle = new Array() ; 						 
			eTitle = text.split('::') ;	
			var title = eTitle[0] ? eTitle[0] : '' ;
			var desc  = eTitle[1] ? eTitle[1] : '' ;
			if ( title != '' && desc != '' ) {
				e.store('tip:title', title );
				e.store('tip:text',  desc  );
				//console.log( 'titulo : ' + e.retrieve('tip:title') ) ;
				//console.log( 'description : ' + e.retrieve('tip:text')) ;
				e.set('alt' , '' ) ;
			}
		}
		
	} );
	

	var _Tips = new Tips( 'img.ttips' , { showDelay: SIMPLE_TIP_SHOWTIME , hideDelay: 50, offsets: {x: -65, y: 12 }, fixed: false });
	
	try {$$('embed').each(function(e){ e.set("wmode","transparent"); e.getParent('div').setStyle('z-index' , 5) ; });} catch(e) {}

	/*	
	$$('.tags a').each( function(e){
		e.setStyle('font-size' , parseInt(String(e.getStyle('font-size')).replace('px','')) - 5 + 'px');
	});
	*/
   
});





function togglePanels ( panelsOn , panelsOff ) {
	
	panelsOff.each(function(e){
		if ( $(e) ) {
			e  = $(e);
			e.set('tween', {duration : 1});
			e.fade('hide');
			e.setStyle('display','none');
		}
	});
	
	panelsOn.each(function(e){
		if ( $(e) ) {
			e  = $(e);
			e.setStyle('display','');
			e.set('tween', {duration : 500});
			e.fade('in');
		}
	});
	
} 



