﻿
(function($) {        
    $.fn.extend({
        EFAudio: function( options ) {        
         var opt = {            
            
         };
         return this.each(function() {
         var obj = $(this);           
         
         obj.opt = opt;         
         $.extend( obj.opt, options);    
                                            
         obj.initialize = function () {
        	 var src = obj.attr('src');
        	 var name = src.split('/');
        	 var name = name[ name.length - 1];
        	 var ins = Math.round( Math.random() * 1000 );
        	 var tmpl = 
        		 '<div id="jquery_jplayer_'+ins+'" class="jp-jplayer"></div>'+
				'		<div id="jp_container_'+ins+'" class="jp-audio">'+
				'			<div class="jp-type-single">'+
				'				<div class="jp-gui jp-interface">'+
				'					<ul class="jp-controls">'+
				'						<li><a href="javascript:;" class="jp-play" tabindex="1">play</a></li>'+
				'						<li><a href="javascript:;" class="jp-pause" tabindex="1">pause</a></li>'+
				'						<li><a href="javascript:;" class="jp-stop" tabindex="1">stop</a></li>'+
				'						<li><a href="javascript:;" class="jp-mute" tabindex="1" title="mute">mute</a></li>'+
				'						<li><a href="javascript:;" class="jp-unmute" tabindex="1" title="unmute">unmute</a></li>'+
				'						<li><a href="javascript:;" class="jp-volume-max" tabindex="1" title="max volume">max volume</a></li>'+
				'					</ul>'+
				'					<div class="jp-progress">'+
				'						<div class="jp-seek-bar">'+
				'							<div class="jp-play-bar"></div>'+
				'						</div>'+
				'					</div>'+
				'					<div class="jp-volume-bar">'+
				'						<div class="jp-volume-bar-value"></div>'+
				'					</div>'+
				'					<div class="jp-current-time"></div>'+
				'					<div class="jp-duration"></div>'+
				'					<div class="jp-title">'+
				'						<ul>'+
				'							<li>'+name+'</li>'+
				'						</ul>'+
				'					</div>'+
				'					<ul class="jp-toggles">'+
				'						<li><a href="javascript:;" class="jp-repeat" tabindex="1" title="repeat">repeat</a></li>'+
				'						<li><a href="javascript:;" class="jp-repeat-off" tabindex="1" title="repeat off">repeat off</a></li>'+
				'					</ul>'+
				'				</div>'+
				'				<div class="jp-no-solution">'+
				'					<span>Update Required</span>'+
				'					To play the media you will need to either update your browser to a recent version or update your <a href="http://get.adobe.com/flashplayer/" target="_blank">Flash plugin</a>.'+
				'				</div>'+
				'			</div>'+
				'		</div>';
        	 
        	obj.before( tmpl );
        	$("#jquery_jplayer_"+ins).jPlayer({
				ready: function () {
					$(this).jPlayer("setMedia", {
								mp3: src								
							});
						},
						cssSelectorAncestor: "#jp_container_"+ins,
						swfPath: "/public/scripts/jplayer",
						supplied: "mp3",
						wmode: "window"
			});
         };
         
         
         obj.initialize();
         }); 
    	}
    });
})(jQuery); 


(function($) {        
    $.fn.extend({
        EFVideo: function( options ) {        
         var opt = {            
            
         };
         return this.each(function() {
         var obj = $(this);           
         var opt = {
        		 width: '295px',
        		 height: '200px'
         }
         
         obj.opt = opt;         
         $.extend( obj.opt, options);    
                                            
         obj.initialize = function () {
        	 var src = obj.attr('src');
        	 var youtubeId = src.replace(/^(.*)\//, '');
        	 var width = obj.attr('width');
        	 var height  = obj.attr('height');
        	 
        	 var ins = Math.round( Math.random() * 1000 );
        	         	
        	 var tmpl = '<a id="play_'+ins+'" href="#" class="youtube" style="position:relative; display: block">'+
        	 '<img src="http://img.youtube.com/vi/'+youtubeId+'/0.jpg" width="'+obj.opt.width+'"/>'+        	         	
        	 '<img style="position:absolute; top:0px; left: 0px" src="/public/images/video2.png"  width="'+obj.opt.width+'"/></a>';        	         	
        	 obj.before( tmpl );        	
        	 $('#play_'+ins).click( function() {
        		 $.colorbox({html:'<iframe width="'+width+'" height="'+height+'" src="'+src+'"  frameborder="0" style="border:none"></iframe>'});
        		 console.log( src, width, height );
        		 return false;
        	 });
         };
         
         
         obj.initialize();
         }); 
    	}
    });
})(jQuery); 


(function(window, $, PhotoSwipe){
	$(document).ready(function(){
	
		var deviceAgent = navigator.userAgent.toLowerCase();
		var agentID = deviceAgent.match(/(iphone|ipod|ipad|android)/);
		// override; 
		// agentID = true;
		
		if (agentID) {
		 		var options = {};
		 		
		 		if ( $("#Gallery a").length ) {
		 			$("#Gallery a").photoSwipe(options);
				
				$('.triggerswipe a').click( function() {
					$('#Gallery a:first').trigger('click');
					return false;
				});
				
		 		}
				
		} else {
			// LIGHTBOX
			$('a.lightbox').lightBox({
				txtImage : ' ',
				txtOf	: '/',
				overlayBgColor : '#000',
				imageLoading:			'/public/images/lightbox-ico-loading.gif',		// (string) Path and the name of the loading icon
				imageBtnPrev:			'/public/images/lightbox-btn-prev.gif',			// (string) Path and the name of the prev button image
				imageBtnNext:			'/public/images/lightbox-btn-next.gif',			// (string) Path and the name of the next button image
				imageBtnClose:			'/public/images/lightbox-btn-close.gif',		// (string) Path and the name of the close btn
				imageBlank:				'/public/images/lightbox-blank.gif',
				overlayOpacity: 0.95
					
			});
		}
		
		$('audio').EFAudio();
		$('video').EFVideo();
		
	});
}(window, window.jQuery, window.Code.PhotoSwipe));
