//::::::::::::::::::::::::::::::::::::::::
//
//	Nom:		gestMovie.js
//	créé le:	14.07.2011
//	par:		Normand Pazzi
//	
//	Description:
//
//				Script  pour les évenements
//				de la page video
//
//::::::::::::::::::::::::::::::::::::::::

var timer = false;

var videopath = "http://www.selfrag.com/";
var swfplayer = videopath + "video/flowplayer-3.2.7.swf";

(function(){
	
	var gestMovie = {
		
		scrollEvent:function(event){
				
			   var delta = 0;
			   var dragScroll = document.getElementById('dargScroll');
			   var dragTop = dragScroll.offsetTop - dragScroll.parentNode.offsetTop;
			   
       		   if (!event)event = window.event;
        	   if (event.wheelDelta) { 
                	delta = event.wheelDelta;
               		if (window.opera)delta = -delta;
			   
        		} 
				else if (event.detail) {
                	delta = -event.detail;
        		}

				dragScroll.style.top = this.scrollTop * dragScroll.parentNode.offsetHeight / this.scrollHeight + 'px';

		},
		
		curPosition:function(e){
			
			this.x = (navigator.appName.substring(0,3) == "Net") ? e.pageX : event.x+document.body.scrollLeft;
			this.y = (navigator.appName.substring(0,3) == "Net") ? e.pageY : event.y+document.body.scrollTop;
			
			return this;
		}
		
	};
	
	if(!window.gest){window.gest = gestMovie;}
		  
})();

function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}

window.onload = function(){
	
	 
	 
	var  ctnVid =  document.getElementById('ctnVideo');
	var dragScroll = document.getElementById('dargScroll');
		dragScroll.style.height = (ctnVid.offsetHeight / ctnVid.scrollHeight) * 450 + 'px';
	
	var MsVer = getInternetExplorerVersion();
		
	var dragTop = (MsVer<0)?ctnVid.offsetTop:document.getElementById('contenuVideo').offsetTop
	var domTop  = (MsVer>=0)?document.getElementById('contenuVideo').offsetTop*2:document.getElementById('contenuVideo').offsetTop + 100
	var dragPosAbs = dragScroll.offsetTop;
	
	 dragScroll.onmousedown = function(e){
		 
		 var y1 = gest.curPosition(e).y;
		 var y2 = false;
		 var tmpy1 = gest.curPosition(e).y;
		 
		
		 
		 var masquer = document.createElement('div');
		 	  masquer.style.position = 'absolute';
			  masquer.style.top = 0 + 'px';
			  masquer.style.left = 0+ 'px';
			  masquer.style.height = 100 + '%';
			  masquer.style.width = 100 + '%';
			  masquer.style.background = '#000';
			  masquer.style.opacity = 0;
			  masquer.style.filter = 'alpha(opacity=0)';
			  masquer.style.zIndex = 1000;
			  
			  document.body.appendChild(masquer);
		
		 document.onmousemove = function(e){
			 
			 (!y2)?y2 = gest.curPosition(e).y:''
			 y1 = gest.curPosition(e).y;
			 
			 if(y1 - (tmpy1-dragScroll.offsetTop) > dragTop){
				 if(y1 + ((dragScroll.offsetTop - domTop + dragScroll.offsetHeight) - tmpy1) < ctnVid.offsetHeight){
					dragScroll.style.top = (dragScroll.offsetTop - dragPosAbs) + (y1-y2)  + 'px';
			 		ctnVid.scrollTop = (dragScroll.offsetTop - dragPosAbs) / (dragScroll.parentNode.offsetHeight / ctnVid.scrollHeight);
				 }
				 else{
					dragScroll.style.top = ctnVid.offsetHeight - dragScroll.offsetHeight + 'px';
			 		ctnVid.scrollTop = ctnVid.scrollHeight;
				 }
			 }
			 else{
				 dragScroll.style.top = 0  + 'px';
			 	 ctnVid.scrollTop = 0;
			 }
			 
			 y2 = gest.curPosition(e).y;
			 
		 }
		 
		 document.onmouseup = function(){masquer.parentNode.removeChild(masquer); document.onmousemove = function(){}}
		 
	 }
	 
	 
	 
	 if(document.addEventListener){
		 ctnVid.addEventListener('DOMMouseScroll', gest.scrollEvent, false);
	 }
	
	ctnVid.onmousewheel = ctnVid.onmousewheel = gest.scrollEvent;
	
	

							  
}

	$(document).ready(function(){
		$("a[rel^='prettyPhoto']").prettyPhoto({
			animation_speed: 'fast', /* fast/slow/normal */
			slideshow: 5000, /* false OR interval time in ms */
			autoplay_slideshow: false, /* true/false */
			opacity: 0.80, /* Value between 0 and 1 */
			show_title: true, /* true/false */
			allow_resize: true, /* Resize the photos bigger than viewport. true/false */
			default_width: 800,
			default_height: 400,
			counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
			theme: 'pp_default', /* light_rounded / dark_rounded / light_square / dark_square / facebook */
			horizontal_padding: 20, /* The padding on each side of the picture */
			hideflash: false, /* Hides all the flash object on a page, set to TRUE if flash appears over prettyPhoto */
			wmode: 'opaque', /* Set the flash wmode attribute */
			autoplay: true, /* Automatically start videos: True/False */
			modal: false, /* If set to true, only the close button will close the window */
			deeplinking: true, /* Allow prettyPhoto to update the url to enable deeplinking. */
			overlay_gallery: true, /* If set to true, a gallery will overlay the fullscreen image on mouse over */
			keyboard_shortcuts: true, /* Set to false if you open forms inside prettyPhoto */
			changepicturecallback: function(){}, /* Called everytime an item is shown/changed */
			callback: function(){}, /* Called when prettyPhoto is closed */
			ie6_fallback: true,
			markup: '<div class="pp_pic_holder"> \
						<div class="ppt">&nbsp;</div> \
						<div class="pp_top"> \
							<div class="pp_left"></div> \
							<div class="pp_middle"></div> \
							<div class="pp_right"></div> \
						</div> \
						<div class="pp_content_container"> \
							<div class="pp_left"> \
							<div class="pp_right"> \
								<div class="pp_content"> \
									<div class="pp_loaderIcon"></div> \
									<div class="pp_fade"> \
										<a href="#" class="pp_expand" title="Expand the image">Expand</a> \
										<div class="pp_hoverContainer"> \
										</div> \
										<div id="pp_full_res"></div> \
										<div class="pp_details"> \
											<p class="pp_description"></p> \
											{pp_social} \
											<a class="pp_close" href="#">Close</a> \
										</div> \
									</div> \
								</div> \
							</div> \
							</div> \
						</div> \
						<div class="pp_bottom"> \
							<div class="pp_left"></div> \
							<div class="pp_middle"></div> \
							<div class="pp_right"></div> \
						</div> \
					</div> \
					<div class="pp_overlay"></div>',
			gallery_markup: '',
			image_markup: '<img id="fullResImage" src="{path}" />',
			flash_markup: '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="{width}" height="{height}"><param name="wmode" value="{wmode}" /><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="{path}" /><embed src="{path}" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="{width}" height="{height}" wmode="{wmode}"></embed></object>',
			quicktime_markup: '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" height="{height}" width="{width}"><param name="src" value="{path}"><param name="autoplay" value="{autoplay}"><param name="type" value="video/quicktime"><embed src="{path}" height="{height}" width="{width}" autoplay="{autoplay}" type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/"></embed></object>',
			iframe_markup: '<iframe src ="{path}" width="{width}" height="{height}" frameborder="0" scrolling="no" allowTransparency="true" style="background:#000;"></iframe>',
			inline_markup: '<div class="pp_inline">{content}</div>',
			custom_markup: '',
			social_tools: '' /* html or false to disable */
		});
	});

