// JavaScript Document

		
window.addEvent('domready',function() 
{
					
	/*----------------------------------------------
	| By Gallery
	-----------------------------------------------*/
	showImageBig(0);
	
	/*----------------------------------------------
	| Add Event in images gallery
	-----------------------------------------------*/
	$$('.gallery_images').addEvents({
		click: function() 
		{
			
			$$('.gallery_images').removeClass('activo');						
			var path   =        this.getProperty('href');
			var description =   this.getProperty('title');
			var title       =   this.getChildren().getProperty('title');
			
			this.addClass('activo');
			$$("#big_image").setProperty('src', path);   
			$$("#big_title").set('html',title);                    
			$$("#big_description").set('html',description);                   
			return false;
		}
	});
				
	
	/*----------------------------------------------
	| Add Event Next in Gallery 
	-----------------------------------------------*/
	$$('.next').addEvents({
		click: function() {
			var j     = 0;
			var count =   $$('.gallery_images').length;
			$$('.gallery_images').each(function(el,i){     

								   
			if(  el.match('.activo') ) 
			{ 
				j = i;                     
			}                    
			});   
			var total = j+1;
			
			if(count == total){ j=0 }else{ j = j+1}     
			showImageBig(j);					
		}
	});
				
	/*----------------------------------------------
	| Add Event Previos in Gallery 
	-----------------------------------------------*/			
	$$('.previous').addEvents({
		click: function() {
			 var j     = 0;
			 var count =   $$('.gallery_images').length;
			 $$('.gallery_images').each(function(el,i){            
				if(   el.match('.activo') ) 
				{ 
				  j = i;                     
				}                    
			 });   
			 var total = j+1;

			 if(j == 0){ j = count-1 }else{ j = j-1}     
			showImageBig(j);					
		}
	});		
	
	
	
	/*------------------------------------------------------------------------------------------------------*/
	
	/*----------------------------------------------
	| By Hot-Shots
	-----------------------------------------------*/	
	var characters = ['larry_hotshot', 'shelley_hotshot', 'cashmere_hotshot', 'weasel_hotshot','sebastian_hotshot','mummy_hotshot'];
	var viewrandom = ['larry_hotshot', 'shelley_hotshot', 'cashmere_hotshot', 'weasel_hotshot','sebastian_hotshot','mummy_hotshot'].getRandom();              
	//$$('.'+viewrandom).removeClass('hidemyass');
	$$('.larry_hotshot').removeClass('hidemyass');
	var current  =  $$('#img_white').getFirst();	

	$$('.view_hotshot').addEvents({
		'mouseover': function(){ 
			var name = this.getProperty('alt');                                                
			this.setProperty('src', 'http://pmz.tv/wp-content/themes/Belonna/images/'+name+'_im_ho.jpg');
		},
		'mouseleave':function(){
			if(!this.match('.viewed')){
			var name = this.getProperty('alt');                                                
			this.setProperty('src', 'http://pmz.tv/wp-content/themes/Belonna/images/'+name+'_im.jpg');
			}
		},
		'click': function() { 
			if(current != ''){
				current.setProperty('src', 'http://pmz.tv/wp-content/themes/Belonna/images/'+current.getProperty('alt')+'_im.jpg');
			}
			$$('.view_hotshot').removeClass('viewed');
			this.addClass('viewed');	
			var name = this.getProperty('alt');                                             
			
			this.setProperty('src', 'http://pmz.tv/wp-content/themes/Belonna/images/'+name+'_im_ho.jpg');
			
			characters.each(function(el,i) { 
				$$('.'+el).addClass('hidemyass');       
			});
			
			current = this;					
			$$('.'+name+'_hotshot').removeClass('hidemyass'); 
		}
   });



   $$('.thumbs').setStyles({ cursor: 'pointer'}).addEvents({
		'mouseover': function()
		{ 
			this.getParent().removeClass('thumbs_off').addClass('thumbs_on'); 
			},
			'mouseleave':function(){
			if(!this.match('.thumbviewed'))
			{
			this.getParent().removeClass('thumbs_on').addClass('thumbs_off'); 
			}
							  
		},
		'click': function() 
		{ 
				$$('.thumbs').each(function(el,i){  
					el.getParent().removeClass('thumbs_on').addClass('thumbs_off'); 
					el.removeClass('thumbviewed');
				});   

				this.addClass('thumbviewed');	
				this.getParent().removeClass('thumbs_off').addClass('thumbs_on'); 
				var gallery = this.getProperty('title');
				var alt    = this.getProperty('alt');
				var id     = this.getProperty('id');
				var name   = alt+'_large0'+id+'.jpg';
				$$('#large_'+alt).setProperty('src','http://pmz.tv/wp-content/themes/Belonna/images/Gallery/'+gallery+'/Large/'+name); 
		}
	});
	
	/*-----------------------------------------------------------------------------------------------------------------------------*/
	
	/*----------------------------------------------
	| By Video
	-----------------------------------------------*/	
		   
	/*----------------------------------------------
	| Add Event Next in Video 
	-----------------------------------------------*/	
	$$('.next_video').addEvents({
		click: function(ev) {
				var j     = 0;
			var count =   $$('.tubepress_thumb').length;
			$$('.tubepress_thumb').each(function(el,i){     

								   
			if(  el.getFirst().match('.activo') ) 
			{ 
				j = i;                     
			}                    
			});   
			var total = j+1;
			
			if(count == total){ j=0 }else{ j = j+1}     
			showVideo(j);					
		}
	});
	
	/*----------------------------------------------
	| Add Event Previos in Video 
	-----------------------------------------------*/	
	$$('.previous_video').addEvents({
		click: function() {
			var j     = 0;
			 var count =   $$('.tubepress_thumb').length;
			 $$('.tubepress_thumb').each(function(el,i){            
				if(  el.getFirst().match('.activo') ) 
				{ 
				  j = i;                     
				}                    
			 });   
			 var total = j+1;

			 if(j == 0){ j = count-1 }else{ j = j-1}     
			showVideo(j);				
		}
	});
		
		
		
		
	
});

/*----------------------------------------------
| Function by show images in Gallery
-----------------------------------------------*/
function showImageBig(j)
{
   
   $$('.gallery_images').removeClass('activo'); 
   $$('.gallery_images').each(function(el,i){ 
		if( i==j ) 
		{                                   
		 var path         =     el.getProperty('href');
		 var description  =     el.getProperty('title');
		 var title        =   el.getChildren().getProperty('title');
		 el.addClass('activo');
		 $$("#big_image").setProperty('src', path);   
		 $$("#big_title").set('html',title);                    
		 $$("#big_description").set('html',description);                          
	   }                  
	});   
}
		

/*----------------------------------------------
| Function by show Video
-----------------------------------------------*/
function showVideo(j)  
{
	 $$('.tubepress_thumb').each(function(el,i){ 
		 if( i==j ) 
		 {  
				var videoId   = el.getFirst().getProperty('alt');
				var playerName = 'normal';
				var  embeddedName = 'youtube';          
				//var galleryId = el.getFirst().getProperty('title');   
				var galleryId = el.getProperty('id');     						
				tubepress_normal_player(galleryId, videoId); 
				/* swap the gallery's embedded object */
				TubePress.swapEmbedded(galleryId, videoId, embeddedName);
				
				/* then call the player to load up / play the video */
				TubePress.callPlayerJs(galleryId, videoId, embeddedName, playerName);                          
		 }                  
	 });   
 }		
 
function tubepress_normal_player(galleryId, videoId) {  
        
		var videoTitleAnchor = jQuery("#tubepress_title_" + videoId + "_" + galleryId);
        var videoDescriptionAnchor = jQuery("#tubepress_description_" + videoId + "_" + galleryId);

		var clicked = jQuery("#tubepress_image_" + videoId + "_" + galleryId);
		
		embeddedTitleId = "#tubepress_embedded_title_" + galleryId;
		embeddedDescriptionId = "#tubepress_embedded_description_" + galleryId;
		
        mainTitleDiv = jQuery(embeddedTitleId); 
        mainTitleDiv.html( videoTitleAnchor.html() );
		
		mainDescriptionDiv = jQuery(embeddedDescriptionId); 
        mainDescriptionDiv.html( videoDescriptionAnchor.html() );
		
		jQuery('.tubepress_thumb').children().removeClass('activo');
		clicked.addClass('activo');
		
        //jQuery(embeddedTitleId)[0].scrollIntoView(true);
		//jQuery(embeddedDescriptionId)[0].scrollIntoView(true);
}



function initVideo(id)  
{

	 $$('.tubepress_thumb').each(function(el,i){ 
		 if( el.getFirst().match('[alt='+id+']') )
		 {  
				var videoId   = el.getFirst().getProperty('alt');
				var galleryId = el.getProperty('id');   
                $$("#tubepress_image_" + videoId + "_" + galleryId).addClass('activo');	 	
				
		 }                  
	 });   
 }		

