jQuery.noConflict();
jQuery(document).ready(function($){

  $('#sidebar link, #sidebar script, #content script,  #content link').remove();  

/* Portfolio Tabs Page */
  for ( i = 0 ; i < $('li.portfolio-skeleton').size()*2; i++) {
    $("div.css-panes").append("<div></div>");
  }
 
  $("ul.css-tabs").tabs("div.css-panes > div", {
    effect: 'fade',
    onBeforeClick: function(event, i) {
      $('a.current').parent().removeClass('active-tab'); 
      var pane = this.getPanes().eq(i);
      if (pane.is(":empty")) {
        pane.load(this.getTabs().eq(i).attr("href"), function() {
        
          $(this).find('link, title').remove();

          $(this).find('.videoembed').each( function() {
            var source =  $(this).attr('href');
			if (source == "") {
				$(this).remove();
			} else {
            	$f($(this).attr("id"), "/js/flowplayer.commercial-3.1.5.swf", {
							key: '#$0394989467c84ff3b5b',
							logo: null,
							clip: {
                scaling: "fit",
                autoPlay: true,
                autoBuffering: true,
                url: source
              },
			  plugins: {
				controls: {
					url: '/js/flowplayer.controls-tube-3.1.5.swf',height: 20, opacity: 0.75, timeColor: '#870004', progressColor: '#870004', buttonOverColor: '#870004', volumeSliderColor: '#870004', autoHide: 'always', timeBgColor: '#888888'
				} 
			  }            
            });
			}
          });
          
          $(this).find('a.flashembed').each( function(){
              var params = eval('(' + $(this).attr('rel') + ')');
              //var params = $.evalJSON($(this).attr('rel'));
              $(this).flashembed( $(this).attr('href'), params );
          });
        
        });
      }
    },
    onClick: function() {
		if (jQuery.browser.msie) { 
  			var currId = $('a.current').parent().attr("id");
      		$('.css-panes').find('.videoembed').each( function() {
				if (currId == ($(this).attr("id") + "_btn")) {
					$f($(this).attr("id")).unmute();
				} else {
		    		$f($(this).attr("id")).mute();	
				}
	  		});
		}
	  $('a.current').parent().addClass('active-tab');
	  $('.sidebar').appendTo('#sidebar .text-container').fadeIn('fast', function(){
      var highestCol = Math.max($('#sidebar').find('.text-container').height(),$('#content').height());
      $('#sidebar').height(highestCol + 30);
    });
    }
  });

  $.easing.custom = function (x, t, b, c, d) { 
      var s = 1.70158;  
      if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b; 
      return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b; 
  }
  $("div.scrollable").scrollable({
    clickable: false,
    easing: 'custom'
  }).navigator().mousewheel();


  Cufon.replace('h1');

	$('#sharethis').hover(
		function(){ return addthis_open(this, '', '[URL]', '[TITLE]'); },
		function(){ addthis_close();  }
	);	
  $('#sharethis').click(function(){ return addthis_sendto(); });

  if( $('#sidebar .text-container').length > 0) {
    $('#sidebar .text-container').html( $('#sidebar .text-container').html().replace('Loading...','') );
  }

  $('.sidebar, .header').hide().css({
    padding: '0',
    background: 'none',
    margin: '0',
    border: 'none'
  });

  $('.header').appendTo('#header-container').fadeIn();

  if( !($('.header').length > 0) ) {
    $('#header-container').hide();
  }

  $('#site-title').prepend('<div id="flashoverlay"></div>');


  $('#nav_14623').addClass('spritesnav').fadeIn('show');


  $('.spritesnav').sprites();
  $('.spritesnav .selected a').removeAttr('style', '');

  $('a[href^="mailto:"]').addClass('email');
  if ($('a.email').length > 0) { $('a.email').defuscate(); }

  $('.spritesnav li li a').click( function() {
    window.location.href = $(this).attr('href');
  });

// External links auto-styler

  $('p a').filter(function() {
    return this.hostname && this.hostname != location.hostname;
  }).addClass('external');

  $('a.external').click(function(){
    window.open(this.href);
    return false;
  });

// Button styling

  $('button').hover( function() { $(this).css ('cursor', 'pointer'); });

	$('.submitBtn').hover(
		function(){ $(this).addClass('submitBtnHover'); },
		function(){ $(this).removeClass('submitBtnHover'); }
	);	

/* Homepage scripting */


    $('#footer div ul li:last a').css('border-right', 'none');
    $('#copyright ul li:last a').css('border-right', 'none');

/* Sidebar video */

    if( $('#player-sidebar-link').length > 0) {
      $f("player-sidebar-link", { src: "/js/flowplayer.commercial-3.1.5.swf" , wmode: 'transparent'}, { key: '#$0394989467c84ff3b5b', logo: null, clip: { scaling: 'fit'},  plugins: {controls: { url:'/js/flowplayer.controls-tube-3.1.5.swf', height: 15, opacity: 0.75, timeColor: '#870004', progressColor: '#870004', buttonOverColor: '#870004', volumeSliderColor: '#870004', fullscreen: true, autoHide: 'always', time: false } } });
    }

    if( $('#player-sidebar-link-2').length > 0) {
      $f("player-sidebar-link-2", { src: "/js/flowplayer.commercial-3.1.5.swf" , wmode: 'transparent'}, { key: '#$0394989467c84ff3b5b', logo: null, clip: { scaling: 'fit'},  plugins: {controls: { url:'/js/flowplayer.controls-tube-3.1.5.swf', height: 15, opacity: 0.75, timeColor: '#870004', progressColor: '#870004', buttonOverColor: '#870004', volumeSliderColor: '#870004', fullscreen: true, autoHide: 'always', time: false } } });
    }

/* Overlays */

    $("a.overlay").each( function() {
      if( !$(this).hasClass('overlay-vid')) {
        $(this).overlay({ 
          expose: { 
              color: '#333', 
              loadSpeed: 200, 
              opacity: 0.9
          } 
        });
      }  
    });

   
    $('#CAT_Search').attr('value', 'Search');
    
// Addthis button

	$('.opacity50').hover(
		function(){ $(this).fadeTo('fast', 1); },
		function(){ $(this).fadeTo('fast', 0.5);  }
	);	

	$('.opacity75').hover(
		function(){ $(this).fadeTo('fast', 1); },
		function(){ $(this).fadeTo('fast', 0.75);  }
	);	

  if( $('.cycle').length > 0) { $('.cycle').cycle(); }


// Swap value text form

    var swapValues = [];
    $(".swap-value").each(function(i){
        swapValues[i] = $(this).val();
        $(this).focus(function(){
            if ($(this).val() == swapValues[i]) {
                $(this).val("");
            }
        }).blur(function(){
            if ($.trim($(this).val()) == '') {
                $(this).val(swapValues[i]);
            }
        });
    });  

        $("#announcements").scrollable({ 
            vertical:true,  
            size: 2 
        }).navigator().mousewheel().autoscroll({ 
            steps: 2,
            interval: 12000
        });     


/* ALL VIDEO LOAD AFTER WINDOW LOADS */

/*$(window).load(function () {

  
});*/

    if ($('#homepage').length > 0) {

      $f( "player", { src: "/js/flowplayer.commercial-3.1.5.swf", wmode: "transparent", id: "player-obj", width: "640", height: "190", allowfullscreen: 'false'}, {
      key: '#$0394989467c84ff3b5b' , logo: null,
        clip: {      
          autoBuffering: true,
          autoPlay: true,
          bufferLength: 5,
          fadeInSpeed: 2500,
          url: '/flv/promo.f4v'
        },
        plugins: { controls: null } }).onFinish( function(){

          $('#player').fadeOut( 'slow' );
          $('#player-cycle').after('<a id="play-video" href="#" class="opacity50">Replay intro</a> <a id="view-map" href="#" class="opacity50">View map</a>');
          $('#view-map, #play-video').hover(
            function(){ $(this).fadeTo('fast', 1); },
            function(){ $(this).fadeTo('fast', 0.5);  }
          );	
          $('#play-video').click( function() {
            $('#player-cycle, #view-map, #play-video').fadeOut( 'fast', function() {
              $('#view-map, #play-video').remove();
              $('#player').fadeIn('fast', function () {
                $f("player").play();
              });
            });
          });
          $('#player-cycle').fadeIn( 'fast', function() {
            $(this).before('<ul id="nav-cycle">').cycle({
              pager: '#nav-cycle',
              pagerAnchorBuilder: function(idx, slide) { 
                return '<li><a href="#"></a></li>'; 
 /*               return '#nav-cycle li:eq(' + idx + ') a'; */
              } 
            }).after('</ul>');
          });
          $("#view-map").click( function() {
            $('#nav-cycle li:eq(1) a').trigger('click'); 
            return false; 
          });
          
        });
	 if ($('#player-dtv-launch').length > 0) {
	  $f("player-dtv-launch", { src: "/js/flowplayer.commercial-3.1.5.swf", wmode: 'transparent', id: "player-sidebar-obj2", allowfullscreen: 'false' }, {
      key: '#$0394989467c84ff3b5b', logo: null, play: null,
          clip: {      
            scaling: 'scale',
            url: '/flv/DavidIntroDTVLaunch.flv',
            fadeInSpeed: 0,
            onFinish: function () { 
              this.unload();
            } 
          }, 
          canvas: { backgroundColor: "#ffffff" },
          plugins: { controls: null }
          }
        ); 
		};
	  if ($('#player-sidebar').length > 0) {
      $f("player-sidebar", { src: "/js/flowplayer.commercial-3.1.5.swf", wmode: 'transparent', id: "player-sidebar-obj", allowfullscreen: 'false' }, {
      key: '#$0394989467c84ff3b5b', logo: null, play: null,
          clip: {      
            scaling: 'scale',
            url: '/flv/DavidIntro.flv',
            fadeInSpeed: 0,
            onFinish: function () { 
              this.unload();
            } 
          }, 
          canvas: { backgroundColor: "#ffffff" },
          plugins: { controls: null }
          }
        );   
	  };
	  
	 
	   
        $('#video-title').html( '&laquo; <b>David Seton &mdash; CEO</b><br />Olympus Pacific Minerals Incorporated' );

        
    }
   


  function addMega(){
    $(this).find('ul').css('left', $(this).find('a').css('left')).fadeIn(50);
    $(this).find('a').show();
    $(this).find('li').show();
  }

  function removeMega(){
    $(this).find('ul').hide();
    $(this).find('ul a').hide();
    $(this).find('ul li').hide();
  } 

  $('.mega, .selected').hoverIntent( {
    interval: 100,
    sensitivity: 4,
    over: addMega,
    timeout: 0,
    out: removeMega
  });

  $('#ticker-flash').flashembed({ src: "/swf/stock-ticker.swf", wmode: "transparent" });
  
  $('#dtv-widget').flashembed({ src: "/swf/MeetingsWidget.swf", wmode: "transparent" });

  if( $("#flashoverlay").length > 0) { 
    $('#flashoverlay').flashembed({ src: "/swf/waves.swf", wmode: "transparent" } ); 
  };
  
  if( $('#flash-growth-graph').length > 0) {
    $('#flash-growth-graph').flashembed("/swf/FCF_StackedArea2D.swf", { dataURL: "/swf/production_forcast_data.xml", chartWidth: "557", chartHeight: "400", wmode: 'transparent' });
  }
  

/* Gallery Flipping BC! */

  if( $('.photogalleryTable').length > 0 ){
    $('.photogalleryNavigation').append( ' ' + $('table.photogalleryTable tr:first td').size() * ( $('table.photogalleryTable tr').size() - 1 ) + ' of ' + $('.photogalleryTable a[rel=lightbox[9146]]').size() );
    $('table.photogalleryTable').after('<div id="gallery-replacement"></div><p id="gallery-replacement-num"></p>');
    $('#gallery-replacement-num').html($('table.photogalleryTable td:last').html());
    $('table.photogalleryTable').find('a').appendTo('#gallery-replacement');

    $('table.photogalleryTable').remove();
   
    $('table.photogalleryTable').remove();
    
    $('#gallery-replacement a:contains("Next")').remove();
    $('#gallery-replacement a:contains("Previous")').remove();
    $('#gallery-replacement a').removeAttr('rel');
    $('#gallery-replacement a').removeAttr('onclick');
    
    $('#gallery-replacement a:nth-child(3n)').css('padding-right', '0');
    
    $('#gallery-replacement a').overlay({
      target: '#gallery_overlay', 
      expose: '#333333',
      onBeforeLoad: function(){
        $('#flash-growth-graph').after('<div id="temp-holder"></div>');
        $('#temp-holder').css('height', $('#flash-growth-graph').height() + 'px');
        $('#temp-holder').css('width', $('#flash-growth-graph').width() + 'px');
        
        $('#flash-growth-graph').hide();
      },
      onClose: function(){
        $('#temp-holder').remove();
        $('#flash-growth-graph').show();
      }
    }).gallery({
       speed: 800
    });
  }

  $(window).load(function(){
    $('#atff').parent().hide();
    $('.sidebar').appendTo('#sidebar .text-container').fadeIn('fast', function(){
      var highestCol = Math.max($('#sidebar').find('.text-container').height(),$('#content').height());
      $('#sidebar').height(highestCol + 30);
    });
    $('#atff').hide();
  });

$('.videoembed_media:empty').remove(); 
jQuery(document).find('.videoembed_media').each( function() {
  source =  jQuery(this).children().attr('href');
  jQuery(this).html('<object height="100%" width="100%" type="application/x-shockwave-flash" data="/js/flowplayer.commercial-3.1.5.swf"><param value="true" name="allowfullscreen"/><param value="always" name="allowscriptaccess"/><param value="high" name="quality"/><param value="transparent" name="wmode"/><param value="false" name="cachebusting"/><param value=\'config={"key":"#$0394989467c84ff3b5b","logo":null,"clip":{"scaling":"fit","autoPlay":true,"autoBuffering":true,"url":"'+source+'"},"plugins":{"controls":{"url":"/js/flowplayer.controls-tube-3.1.5.swf"}}}\' name="flashvars"/></object>');
}); 

});