﻿
// start-up calls
$(document).ready(function () {
  //$("#wrap-fade-nav").css({ opacity: 0.5 });
  $("#head-spot-fade").css({ opacity: 0.7 });
  $("#slide-comment").css({ opacity: 0.7 });
  $("#wrap-fade-title").css({ opacity: 0.9 });
  $("#wrap-fade-tabs").css({ opacity: 0.9 });

  $("#eq-footer").equalHeights();
  $(".eq").equalHeights();

  $(".img-fader img").fadeTo("fast", 1.0);
  $(".img-fader img").hover(function () {
    $(this).fadeTo("fast", 0.8);
  }, function () {
    $(this).fadeTo("fast", 1.0);
  });

  $(".accordion").tabs(".accordion > .pane", { tabs: 'h2', effect: 'slide', initialIndex: null });
  $(".accordion-dates").tabs(".accordion-dates > .pane-dates", { tabs: 'h2', effect: 'slide', initialIndex: null });

  $("#wrap-main").roundCorners();

  if ($('.header-cycle').length) {
    $('.header-cycle').cycle({
      fx: 'fade',
      before: onBefore,
      after: onAfter,
      speed: 1000,
      pause: 1,
      pager: '#slide-nav',
      timeout: 16000
    });
    $('.header-cycle').css('margin-left', '-2px');
  }

  if ($('.header-patch').length) {
    $('.header-patch').cycle({
      fx: 'fade',
      speed: 1000,
      pause: 1,
      timeout: 16000
    });
    $('.header-patch').css('margin-left', '-2px');
  }

  if ($('.header-item').length) {
    $('.header-item').cycle({
      fx: 'fade',
      speed: 1000,
      pause: 1,
      timeout: 16000
    });
    $('.header-item').css('margin-left', '-2px');
  }

  $('a').bind('focus', function () { if (this.blur) this.blur(); });

  checkBrowser();

//  $(window).bind("resize", function () {
//    var $winwidth = $(window).width();
//    if ($('.header-patch').length) {
//      $('.header-patch div').css('width:', 'auto');
//      $('.header-patch div').css('width:', $winwidth + 'px');
//    }
//    if ($('.header-cycle').length) {
//      $('.header-cycle div').css('width:', 'auto');
//      $('.header-cycle div').css('width:', $winwidth + 'px');
//    }
//    if ($('.header-item').length) {
//      $('.header-item div').css('width:', 'auto');
//      $('.header-item div').css('width:', $winwidth + 'px');
//    }
//  });


});

$(function () {
  $(".tool-tip").tipTip({ maxWidth: "auto", defaultPosition: "top", keepAlive: true, edgeOffset: 0 });
});

$(".fancyvid").click(function () {
  $.fancybox({
    'padding': 0, 'autoScale': false,
    'transitionIn': 'none', 'transitionOut': 'none',
    'title': this.title, 'width': 680, 'height': 495,
    'href': this.href.replace(new RegExp("watch\\?v=", "i"), 'v/index.html'),
    'type': 'swf',    // <--add types here
    'swf': { 'allowfullscreen': 'false' }
  });
  return false;
});

$(".fancybox-vid-button").click(function () {
  $.fancybox({
    'padding': 0, 'autoScale': false,
    'transitionIn': 'none', 'transitionOut': 'none',
    'title': this.title, 'width': 680, 'height': 495,
    'href': this.href.replace(new RegExp("watch\\?v=", "i"), 'v/index.html'),
    'type': 'swf',    // <--add types here
    'swf': { 'allowfullscreen': 'false' }
  });
  return false;
});

$(".fancybox-carousel-button").click(function () {
  $.fancybox($('.carousel-panel').html());
  return false;
});

function onBefore() {
  $('#slide-desc').html('' + this.title + '');
} 

function onAfter() {
  $('#slide-desc').html('' + this.title + '');
}

(function ($) {
  $.fn.roundCorners = function () {
    $(".tc").corner("top 6px");
    $(".tl").corner("tl 6px");
    $(".tr").corner("tr 6px");
    $(".bc").corner("bottom 6px");
  };
})(jQuery);

(function ($) {
  $.fn.vAlign = function () {
    return this.each(function (i) {
      var ah = $(this).height();
      var ph = $(this).parent().height();
      var mh = (ph - ah) / 2;
      $(this).css('margin-top', mh);
    });
  };
})(jQuery);

(function ($) {
  $.fn.vAlignCenter = function () {
    return this.each(function (i) {
      var ah = $(this).width();
      var ph = $(this).parent().width();
      var mh = (ph - ah) / 2;
      $(this).css('margin-left', mh);
    });
  };
})(jQuery);

$.fn.equalHeights = function(px) {
	$(this).each(function(){
		var currentTallest = 0;
		$(this).children().each(function(i){
			if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
		});
		if (!px || !Number.prototype.pxToEm) currentTallest = currentTallest.pxToEm(); //use ems unless px is specified
		if ($.browser.msie && $.browser.version == 6.0) { $(this).children().css({'height': currentTallest}); } // for ie6, set height since min-height isn't supported
		$(this).children().css({'min-height': currentTallest}); 
	});
return this;
};

Number.prototype.pxToEm = String.prototype.pxToEm = function (settings) {
  settings = jQuery.extend({
    scope: 'body',
    reverse: false
  }, settings);
  var pxVal = (this == '') ? 0 : parseFloat(this);
  var scopeVal;
  var getWindowWidth = function () {
    var de = document.documentElement;
    return self.innerWidth || (de && de.clientWidth) || document.body.clientWidth;
  };
  if (settings.scope == 'body' && $.browser.msie && (parseFloat($('body').css('font-size')) / getWindowWidth()).toFixed(1) > 0.0) {
    var calcFontSize = function () {
      return (parseFloat($('body').css('font-size')) / getWindowWidth()).toFixed(3) * 16;
    };
    scopeVal = calcFontSize();
  }
  else { scopeVal = parseFloat(jQuery(settings.scope).css("font-size")); };
  var result = (settings.reverse == true) ? (pxVal * scopeVal).toFixed(2) + 'px' : (pxVal / scopeVal).toFixed(2) + 'em';
  return result;
};

// tabs functions
(function (c) {
  function p(d, b, a) {
    var e = this, l = d.add(this), h = d.find(a.tabs), i = b.jquery ? b : d.children(b), j; h.length || (h = d.children()); i.length || (i = d.parent().find(b)); i.length || (i = c(b)); c.extend(this, { click: function (f, g) {
      var k = h.eq(f); if (typeof f == "string" && f.replace("#", "")) { k = h.filter("[href*=" + f.replace("#", "") + "]"); f = Math.max(h.index(k), 0) } if (a.rotate) { var n = h.length - 1; if (f < 0) return e.click(n, g); if (f > n) return e.click(0, g) } if (!k.length) { if (j >= 0) return e; f = a.initialIndex; k = h.eq(f) } if (f === j) return e;
      g = g || c.Event(); g.type = "onBeforeClick"; l.trigger(g, [f]); if (!g.isDefaultPrevented()) { o[a.effect].call(e, f, function () { g.type = "onClick"; l.trigger(g, [f]) }); j = f; h.removeClass(a.current); k.addClass(a.current); return e }
    }, getConf: function () { return a }, getTabs: function () { return h }, getPanes: function () { return i }, getCurrentPane: function () { return i.eq(j) }, getCurrentTab: function () { return h.eq(j) }, getIndex: function () { return j }, next: function () { return e.click(j + 1) }, prev: function () { return e.click(j - 1) }, destroy: function () {
      h.unbind(a.event).removeClass(a.current);
      i.find("a[href^=#]").unbind("Tourist-Item-Pages/Page-Not-Found2f78.html"); return e
    }
    }); c.each("onBeforeClick,onClick".split(","), function (f, g) { c.isFunction(a[g]) && c(e).bind(g, a[g]); e[g] = function (k) { k && c(e).bind(g, k); return e } }); if (a.history && c.fn.history) { c.tools.history.init(h); a.event = "history" } h.each(function (f) { c(this).bind(a.event, function (g) { e.click(f, g); return g.preventDefault() }) }); i.find("a[href^=#]").bind("Tourist-Item-Pages/Page-Not-Found2f78.html", function (f) { e.click(c(this).attr("href"), f) }); if (location.hash && a.tabs == "a" && d.find("[href=" + location.hash + "]").length) e.click(location.hash);

    else if (a.initialIndex === 0 || a.initialIndex > 0) e.click(a.initialIndex)
  } c.tools = c.tools || { version: "1.2.5" }; c.tools.tabs = { conf: { tabs: "a", current: "current", onBeforeClick: null, onClick: null, effect: "default", initialIndex: 0, event: "click", rotate: false, history: false }, addEffect: function (d, b) { o[d] = b } }; var o = { "default": function (d, b) { this.getPanes().hide().eq(d).show(); b.call() }, fade: function (d, b) { var a = this.getConf(), e = a.fadeOutSpeed, l = this.getPanes(); e ? l.fadeOut(e) : l.hide(); l.eq(d).fadeIn(a.fadeInSpeed, b) }, slide: function (d,
b) { this.getPanes().slideUp(200); this.getPanes().eq(d).slideDown(400, b) }, ajax: function (d, b) { this.getPanes().eq(0).load(this.getTabs().eq(d).attr("href"), b) }
  }, m; c.tools.tabs.addEffect("horizontal", function (d, b) { m || (m = this.getPanes().eq(0).width()); this.getCurrentPane().animate({ width: 0 }, function () { c(this).hide() }); this.getPanes().eq(d).animate({ width: m }, function () { c(this).show(); b.call() }) }); c.fn.tabs = function (d, b) {
    var a = this.data("tabs"); if (a) { a.destroy(); this.removeData("tabs") } if (c.isFunction(b)) b =
{ onBeforeClick: b }; b = c.extend({}, c.tools.tabs.conf, b); this.each(function () { a = new p(c(this), d, b); c(this).data("tabs", a) }); return b.api ? a : this
  }
})(jQuery);

// PNG Fixer
var blank = new Image();
//blank.src = 'App_Themes/DiscoverIreland/images/blank.gif';
blank.src = '';

$(document).ready(function () {
  var badBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
  if (badBrowser) {
    // get all pngs on page
    $('img[src$=.png]').each(function () {
      if (!this.complete) {
        this.onload = function () { fixPng(this) };
      } else {
        fixPng(this);
      }
    });
  }
});

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 checkBrowser() {
  var browser = navigator.userAgent;
  var browserVer = navigator.appVersion;
  var version = parseFloat(browserVer);
  if (browser.indexOf('Firefox/3.0') != -1 && browser.indexOf('Mac') != -1) {
    changeMacFFStyles();
  }
}

function changeMacFFStyles() {
  var o = getElementsByClass('ie6-margin-top-20');
  for (i = 0; i < o.length; i++) {
    o[i].style.marginTop = '-20px';
  }
}

function getElementsByClass(searchClass, node, tag) {
  var classElements = new Array();
  if (node == null)
    node = document;
  if (tag == null)
    tag = '*';

  var els = node.getElementsByTagName(tag);
  var elsLen = els.length;
  var pattern = new RegExp("(^|\\s)" + searchClass + "(\\s|$)");

  for (i = 0, j = 0; i < elsLen; i++) {
    if (pattern.test(els[i].className)) {
      classElements[j] = els[i];
      j++;
    }
  }
  return classElements;
}

jQuery.cookie = function (key, value, options) {

  // key and at least value given, set cookie...
  if (arguments.length > 1 && String(value) !== "[object Object]") {
    options = jQuery.extend({}, options);

    if (value === null || value === undefined) {
      options.expires = -1;
    }

    if (typeof options.expires === 'number') {
      var days = options.expires, t = options.expires = new Date();
      t.setDate(t.getDate() + days);
    }

    value = String(value);

    return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? value : encodeURIComponent(value),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
  }

  // key and possibly options given, get cookie...
  options = value || {};
  var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
  return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};


