// JavaScript Document
var thisTab = '';

// initialize jQuery
jQuery.noConflict();

// on Dom ready
jQuery(function($){
	//var q = 0;
	//$('.right img').each(function() {
	//	q += this.height;
	//});


	var oh = $('.main .right').height(); // original hieght of right DIV
	var ch = $('.main .left .content').height(); // height of content area
	var ihtm = $('.main .right').html(); // innerHTML
	var cat = ''; //concatenate this sting.
	var hist = '[0]'; // revent repeating rnd images.
	var nh = $('.main .right').height(); // new height of the right hand div
	
	if( (ch > 300) || (oh = 0) ) {
		// an array of the random images
		var imgs = new Array();
		var x = 0;
		for ( var i = 0; i <35; i++) { imgs[i]	= ['<a href="/images/right/lrg/h/h-'+(i+1)+'.jpg" class="lbx"><img src="/images/right/tn/h/h-'+(i+1)+'.jpg" alt="Cine Secreto H: ' + (i+1) + '" width="202" height="133"></a>',133]; }
		x =i-1;
		for ( var i=0; i <11; i++) { imgs[x+(i+1)]	= ['<a href="/images/right/lrg/v/v-'+ (i+1)+'.jpg" class="lbx"><img src="/images/right/tn/v/v-'+ (i+1)+'.jpg" alt="Cine Secreto V: ' + (i+1) + '" width="202" height="300"></a>',300]; }
		while (nh < ch	 ) {
				do {
					var r = Math.floor(Math.random()*imgs.length);
					var exists = (hist.indexOf('['+ r +']') >= 0);
				} while( exists )
				hist += '['+ r +']';
				
				cat += imgs[r][0];
				nh 	+= imgs[r][1];
				
				$('.main .right').css('height', nh );
		}
		
		$('.main .right').html( ihtm + cat );
		$('.main .right').css('height', $('.main .left .content').height()+13 );
	}

	$('.context_nav a:path').each(function() {
		$(this).addClass('selected');
	});

	// look for video clip div, find the HREF and react
	// URL MUST be like this ... format: http://www.youtube.com/v/gtm1y-QwU-k&hl=en&fs=1
	$('.playVideo a').each(function() {
		var url = YouTube( this.href.replace('watch?v=', 'v/') );
		$(this).parents('div:first').html( url );

	});
	
	// lightbox gallery
	$('.right a.lbx').lightBox();

});

function YouTube( youTubeURL ) {
	var h = 310;
	var w = 370;
	var embedd = '<object width="'+w+'" height="'+h+'"><param name="movie" value="'+ youTubeURL +'&hl=en&rel=0&border=0"></param><embed src="'+youTubeURL+'&hl=en&rel=0&border=0" type="application/x-shockwave-flash" width="'+w+'" height="'+h+'"></embed></object>';
	return embedd;
}


function insertYouTube( youTubeRef, w, h, sId ) {
	// 	// <object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/bJh1B5Y_XL8&hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/bJh1B5Y_XL8&hl=en&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>
	var embedd = '<object width="'+w+'" height="'+h+'"><param name="movie" value="http://www.youtube.com/v/'+ youTubeRef +'&hl=en&rel=0&border=0"></param><embed src="http://www.youtube.com/v/'+ youTubeRef +'&hl=en&rel=0&border=0" type="application/x-shockwave-flash" width="'+w+'" height="'+h+'"></embed></object>';
	getLayer(sId).innerHTML = embedd;
	return false;
}

function insertRef ( youTubeRef ) {
	var h = 283;
	var w = 370;
	var rtn = '<object width="'+w+'" height="'+h+'"><param name="movie" value="http://www.youtube.com/v/'+ youTubeRef +'&hl=en&rel=0&border=0"></param><embed src="http://www.youtube.com/v/'+ youTubeRef +'&hl=en&rel=0&border=0" type="application/x-shockwave-flash" width="'+w+'" height="'+h+'"></embed></object>';
	getLayer( 'playVideo' ).innerHTML = rtn;
}



function setTab() {
	if (thisTab != '') {
		getLayer(thisTab).className = "selected";
	}
}

function getLayer( strLayerID ) {
	// returns the style element
	var whichLayer = strLayerID;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichLayer );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichLayer];
	
  return elem;
}


