/*!
* Nanocam Javascript v.1.0
* http://www.nanocam.com/
*
* Copyright 2011, Nanocam
* Todos los derechos reservados
*
* Web Design: eMarketPlan
* http://www.emarketplan.com
* Author: Alejandro Rodriguez
* Date: 05.02.2011
*/ 
var blank = new Image();
blank.src = '/site_media/image/blank.gif';

$(document).ready(function(){
	
	// Se cargan las galerias de fotos y de videos, asi como el lightBox
	lanzarGalerias();
	
	//Miramos si se trata de Internet Explorer y si se trata de una version inferior a la 8
	if ($.browser.msie && (parseInt($.browser.version) < 8)) {
		correct_IE();
	}
	var badBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
	if (badBrowser) {
		correct_IE6();		
	}
});

function lanzarGalerias(){

  $("ul.gallery-photo").prettyGallery({
	  itemsPerPage : 5,
	  animationSpeed : 'normal', /* fast/normal/slow */
	  navigation : 'top',  /* top/bottom/both */
	  of_label: ' of ', /* The content in the page "1 of 2" */
	  previous_title_label: 'Previous page', /* The title of the previous link */
	  next_title_label: 'Next page', /* The title of the next link */
	  previous_label: 'Previous', /* The content of the previous link */
	  next_label: 'Next' /* The content of the next link */
  });
  $("ul.gallery-video").prettyGallery({
	  itemsPerPage : 3,
	  animationSpeed : 'normal', /* fast/normal/slow */
	  navigation : 'top',  /* top/bottom/both */
	  of_label: ' of ', /* The content in the page "1 of 2" */
	  previous_title_label: 'Previous page', /* The title of the previous link */
	  next_title_label: 'Next page', /* The title of the next link */
	  previous_label: 'Previous', /* The content of the previous link */
	  next_label: 'Next' /* The content of the next link */
  });
  $("a[rel^='prettyPhoto']").prettyPhoto({
	  show_title: false, /* true/false */
	  counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
	  theme: 'dark_square', /* light_rounded / dark_rounded / light_square / dark_square / facebook */
	  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 */
  });

}
function correct_IE(){
  $("#content").vAlign();
  var int_y = $("#panel-left").height();
  var ext_y = $("#panel-row").height();
  var med = (ext_y - int_y)/2;
  $("#panel-left").css('margin-top',med);
    
  var version = getFlashVersion().split(',').shift();
  
  // control de Adobe Flash Player
  if(version==0){
	  $("#video-player").html('<div id="no-flash" class="png-fix"><h3>This content requires Flash</h3><p>To view this content, Javascript must be enabled, and you need the latest version of Adobe Flash Player.</p><p>Download the free Flash Player now!</p><a href="http://get.adobe.com/flashplayer/" title="Get Flash Player!"><img src="/site_media/image/no_flash/bt_no_flash.png" width="166" height="47" alt="Get Flash Player" /></a></div>');
  }
}
function correct_IE6(){
  // Correccion del menu para IE6
  $("#menu li.menu-active").css('background-image', 'none');
  
  $('img[src$=.png]').each(function() {
	 if (!this.complete) {
	   this.onload = function() { fixPng(this) };
	 } else {
	   fixPng(this);
	 }
   });
  call_fix_png();
  
  // Correciones IE6
  $("#panel-right").width(707);
  $("#contact-address").css('padding','0');
  
  $(".gallery-photo li").css('padding','5px 5px 5px 5px');
  $(".gallery-video li").css('padding','5px 7px 5px 5px');
  
  $(".pg_prev").css('background-image','url("/site_media/image/galeria_web/arrows_i_ie6.jpg")');
  $(".pg_next").css('background-image','url("/site_media/image/galeria_web/arrows_d_ie6.jpg")');
  
  $("#contact-address").css('margin-left','120px');
  $("#contact-address").css('padding','0 10px 0 0');
}

(function ($) {
	$.fn.vAlign = function() {
		return this.each(function(i){
			var h = $(this).height();
			var oh = $(this).outerHeight();
			var mt = (h + (oh - h)) / 2;
			$(this).css("margin-top", "-" + mt + "px");
			$(this).css("top", "50%");
			$(this).css("position", "absolute");
		});
	};
})(jQuery);

function fixPng(png) {
   // get src
   var src = png.src;
   // set width and height
   if (!png.style.width) { png.style.width = $(png).width(); }
   if (!png.style.height) { png.style.height = $(png).height(); }
   // replace by blank image
   png.onload = function() { };
   png.src = blank.src;
   // set filter (display original image)
   png.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
 }
 
 function getFlashVersion(){
  // ie
  try {
    try {
      // avoid fp6 minor version lookup issues
      // see: http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
      var axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6');
      try { axo.AllowScriptAccess = 'always'; }
      catch(e) { return '6,0,0'; }
    } catch(e) {}
    return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1];
  // other browsers
  } catch(e) {
    try {
      if(navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){
        return (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1];
      }
    } catch(e) {}
  }
  return '0,0,0';
}
 function get_player(){
	 AC_FL_RunContent('codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0', 'width', '640', 'height', '385', 'src', ((!DetectFlashVer(9, 0, 0) && DetectFlashVer(8, 0, 0)) ? '/site_media/player/OSplayer' : '/site_media/player/OSplayer'), 'pluginspage', 'http://www.macromedia.com/go/getflashplayer', 'id', 'flvPlayer', 'allowFullScreen', 'true', 'movie', ((!DetectFlashVer(9, 0, 0) && DetectFlashVer(8, 0, 0)) ? '/site_media/player/OSplayer' : '/site_media/player/OSplayer'), 'FlashVars', 'movie=http://nanocam.es/site_media/video/NCAM_web_trailer.flv&amp;btncolor=0x333333&amp;accentcolor=0x668833&amp;txtcolor=0xffffff&amp;volume=70&amp;previewimage=&amp;autoload=on');
}

function call_fix_png(){
$(".png-fix").each(function(){
   var bgIMG = $(this).css('background-image');
   if(bgIMG.indexOf(".png")!=-1){
	  var iebg = bgIMG.split('url("')[1].split('")')[0];
	  jQuery(this).css('background-image', 'none');
	  jQuery(this).get(0).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + iebg + "',sizingMethod='scale')";
   }
});
}
