﻿function search(elemId) {
    window.location = jQuery('#' + elemId).attr('data-searchUrl') + '?q=' + jQuery('#' + elemId).val();
    return false;
}

jQuery(document).ready(function () {

    jQuery('#latest-news-cycle').cycle({ fx: 'blindY' });
    
    if (jQuery('.cycle img').size() > 1) {
        jQuery('.cycle').after('<span id="cycle-nav"></span>').cycle({ pager: '#cycle-nav' });
    }

    jQuery('.icon').each(function () {
        (jQuery(this).hasClass('after')) ? jQuery(this).append('<span class="icn"></span>') : jQuery(this).prepend('<span class="icn"></span>');
    });
    placeholderAsColumn();
    
    //jQuery('.section-summary .title a').on('click', function(event){event.stopPropagation();});
    //jQuery('.section-summary').on('click', function (event) {  console.log(this); jQuery(this).find('.title a').eq(0).trigger('click'); });

    jQuery('.solutions.grid').layout({ type: 'grid', hgap: 20, vgap: 20, columns: 2 });
    jQuery('.job-list .grid').layout({ type: 'grid', hgap: 9, vgap: 9, columns: 2 });

    window.setTimeout(function () { (jQuery('#section-home-3 .a').height() < jQuery('#section-home-3 .b').height()) ? jQuery('#section-home-3 .a').height(jQuery('#section-home-3 .b').height()) : jQuery('#section-home-3 .b').height(jQuery('#section-home-3 .a').height()); }, 500);

    stickyFooter();
    jQuery(window).resize(function () { stickyFooter(); });
    jQuery('body').ajaxComplete(function () { stickyFooter(); });
    window.setTimeout(function () { stickyFooter(); }, 500);

    jQuery("a[rel^='prettyPhoto']").prettyPhoto();
    
    jQuery('.section-layout .summary-content:not(:has(p))').css({'margin-bottom': '1em'});
});

function stickyFooter() {
    if (jQuery(window).height() > jQuery('#page').height() + jQuery('footer').height() + jQuery('#scWebEditRibbon').height()) {
        jQuery('footer').addClass('sticky');
    }
    else {
        jQuery('footer').removeClass('sticky');
    }
}

function placeholderAsColumn() {
    jQuery('.placeholderAsColumn .image-placeholder:has(:not(img))').remove();
    jQuery('.placeholderAsColumn .image-placeholder').each(function () {
        jQuery(this).height(jQuery(this).parents('.placeholderAsColumn').height());
    });
}

(function (a) { a(document).ready(function () { a("body").append('<div id="supersized"></div>') }); a.supersized = function (b) { var c = "#supersized", d = this; d.$el = a(c); d.el = c; vars = a.supersized.vars; d.$el.data("supersized", d); api = d.$el.data("supersized"); d.init = function () { a.supersized.vars.options = a.extend({}, a.supersized.defaultOptions, b); d.options = a.supersized.vars.options; d._build() }; d._build = function () { d._start() }; d._start = function () { if (d.options.start_slide) { vars.current_slide = d.options.start_slide - 1 } else { vars.current_slide = Math.floor(Math.random() * d.options.slides.length) } var f = d.options.new_window ? ' target="_blank"' : ""; imageLink = (api.getField("url")) ? "href='" + api.getField("url") + "'" : ""; var e = a('<img src="' + api.getField("image") + '"/>'); e.appendTo(d.el).wrap('<a class="image-loading activeslide" ' + imageLink + f + "></a>").css("visibility", "hidden"); e.load(function () { d._origDim(a(this)); d.resizeNow(); d.launch() }); d.$el.css("visibility", "hidden") }; d.launch = function () { d.$el.css("visibility", "visible"); a(window).resize(function () { d.resizeNow() }) }; d.resizeNow = function () { return d.$el.each(function () { a("img", d.el).each(function () { thisSlide = a(this); var f = (thisSlide.data("origHeight") / thisSlide.data("origWidth")).toFixed(2); var e = d.$el.width(), h = d.$el.height(), i; if (d.options.fit_always) { if ((h / e) > f) { g() } else { j() } } else { if ((h <= d.options.min_height) && (e <= d.options.min_width)) { if ((h / e) > f) { d.options.fit_landscape && f < 1 ? g(true) : j(true) } else { d.options.fit_portrait && f >= 1 ? j(true) : g(true) } } else { if (e <= d.options.min_width) { if ((h / e) > f) { d.options.fit_landscape && f < 1 ? g(true) : j() } else { d.options.fit_portrait && f >= 1 ? j() : g(true) } } else { if (h <= d.options.min_height) { if ((h / e) > f) { d.options.fit_landscape && f < 1 ? g() : j(true) } else { d.options.fit_portrait && f >= 1 ? j(true) : g() } } else { if ((h / e) > f) { d.options.fit_landscape && f < 1 ? g() : j() } else { d.options.fit_portrait && f >= 1 ? j() : g() } } } } } function g(k) { if (k) { if (thisSlide.width() < e || thisSlide.width() < d.options.min_width) { if (thisSlide.width() * f >= d.options.min_height) { thisSlide.width(d.options.min_width); thisSlide.height(thisSlide.width() * f) } else { j() } } } else { if (d.options.min_height >= h && !d.options.fit_landscape) { if (e * f >= d.options.min_height || (e * f >= d.options.min_height && f <= 1)) { thisSlide.width(e); thisSlide.height(e * f) } else { if (f > 1) { thisSlide.height(d.options.min_height); thisSlide.width(thisSlide.height() / f) } else { if (thisSlide.width() < e) { thisSlide.width(e); thisSlide.height(thisSlide.width() * f) } } } } else { thisSlide.width(e); thisSlide.height(e * f) } } } function j(k) { if (k) { if (thisSlide.height() < h) { if (thisSlide.height() / f >= d.options.min_width) { thisSlide.height(d.options.min_height); thisSlide.width(thisSlide.height() / f) } else { g(true) } } } else { if (d.options.min_width >= e) { if (h / f >= d.options.min_width || f > 1) { thisSlide.height(h); thisSlide.width(h / f) } else { if (f <= 1) { thisSlide.width(d.options.min_width); thisSlide.height(thisSlide.width() * f) } } } else { thisSlide.height(h); thisSlide.width(h / f) } } } if (thisSlide.parent().hasClass("image-loading")) { a(".image-loading").removeClass("image-loading") } if (d.options.horizontal_center) { a(this).css("left", (e - a(this).width()) / 2) } if (d.options.vertical_center) { a(this).css("top", (h - a(this).height()) / 2) } }); if (d.options.image_protect) { a("img", d.el).bind("contextmenu mousedown", function () { return false }) } return false }) }; d._origDim = function (e) { e.data("origWidth", e.width()).data("origHeight", e.height()).css("visibility", "visible") }; d.getField = function (e) { return d.options.slides[vars.current_slide][e] }; d.init() }; a.supersized.vars = { current_slide: 0, options: {} }; a.supersized.defaultOptions = { start_slide: 1, new_window: 1, image_protect: 1, min_width: 0, min_height: 0, vertical_center: 1, horizontal_center: 1, fit_always: 0, fit_portrait: 1, fit_landscape: 0 }; a.fn.supersized = function (b) { return this.each(function () { (new a.supersized(b)) }) } })(jQuery);
