﻿function LoadLightbox(_width, _height) {
    // Load Galleria here for the popup
    Galleria.loadTheme('/includes/galleria/themes/kimball/galleria.kimball.min.js');

    var config = {
        over: function (e) {
            var _this = $(this);
            showLightbox(e, _this.attr('title'), _this.attr('href'), _width, _height);
            return false;
        },
        timeout: 100,
        sensitivity: 7,
        interval: 170,
        out: closeLightboxWithCheck
    };
    $('.lnkViewLarge').hoverIntent(config);
    $('.lnkViewLarge').click(function (e) {
        var _this = $(this);
        showLightbox(e, _this.attr('title'), _this.attr('href'), _width, _height);
        return false;
    });
}

//Open PDF in new window
function openPDF(strURL) {
    //myPage = window.open(strURL,"pdfLarge","height=550, width=400, scrollbars=yes,status=no,resizable=yes,toolbar=no,menubar=no");
    myPage = window.open(strURL, "pdfLarge", "scrollbars=yes,status=no,resizable=yes,toolbar=no,menubar=no");
}


function initializeImageZoom(_width, _height) {
        $(".largeThumbGrid span").hoverIntent(zoomin, zoomout);
        $(".largeThumbGrid span").click(zoomin);
}

function zoomin() {
    $(this).css({ 'z-index': '10' }); /*Add a higher z-index value so this image stays on top*/
    $(this).find('img').addClass("hover").stop() /* Add class of "hover", then stop animation queue buildup*/
	.animate({
	    marginTop: '-140px', /* The next 4 lines will vertically align this image */
	    marginLeft: '-140px',
	    top: '50%',
	    left: '50%',
	    width: '360px', /* Set new width */
	    height: '360px', /* Set new height */
	    padding: '0px', 'border-width':'3px',color:'white','z-index':'11'
	}, 200); /* this value of "200" is the speed of how fast/slow this hover animates */
    $(this).click(zoomout);	
    return false;
}

function zoomout() {
    $(this).css({ 'z-index': '0' }); /* Set z-index back to 0 */
    $(this).find('img').removeClass("hover").stop()  /* Remove the "hover" class , then stop animation queue buildup*/
	.animate({
	    marginTop: '0', /* Set alignment back to default */
	    marginLeft: '0',
	    top: '0',
	    left: '0',
	    width: '185px', /* Set width back to default */
	    height: '185px', /* Set height back to default */
	    padding: '0px'
	}, 400);
}   

function showLightbox(e, mytitle, myhref, width, height) {
    var xOffset = 10,  x;

    if (e.pageX > (width + xOffset)) {
        x = e.pageX - (width + xOffset);
    }
    else {
        x = e.pageX + xOffset;
    }
    jQuery('#dialog-data-form').html('');
    jQuery('#dialog-data-form').load(myhref, function () {
        jQuery('#dialog-form').dialog({
            modal: false,
            show: 100,
            hide: 200,
            position: [x, e.pageY],
            resize: 'auto',
            width: width,
            height: height,
            title: mytitle,
            draggable: false,
            resizable: false,
            close: function () {
                jQuery('#dialog-data-form').html('');
            }
        });
        jQuery('#dialog-form').dialog('open');
    });
    //if the mouse enters the dialog, then we don't want to close the dialog so set dialogHovered to true when dialog is hovered
    jQuery('#dialog-form').data('dialogHovered', 'false');
    jQuery('#dialog-form').hover(function () {
        jQuery('#dialog-form').data('dialogHovered', 'true');
    }, function () { setTimeout(closeLightbox, 100); });
}

function closeLightboxWithCheck() {
    //close the dialog if the dialog doesn't have the mouse in it
    if (jQuery('#dialog-form').data('dialogHovered') != 'true') {
        jQuery('#dialog-form').dialog('close');
    }
}
function closeLightbox() {
    jQuery('#dialog-form').dialog('close');
}

//Swaps the portfolio image
function swapPortfolio(imgObject, imgName) {
    if (document.getElementById) {
        document.getElementById(imgObject).src = imgName;
    }
}

// Add pdf icons to pdf links
jQuery(document).ready(function () {
    
    //stick the footer at the bottom of the page if we're on an iPad/iPhone due to viewport/page bugs in mobile webkit
    if(navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod' || navigator.platform == 'Android')
    {
         $(".footerbg").css("position", "static");
    };
    
});

/**
* hoverIntent r6 // 2011.02.26 // jQuery 1.5.1+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne brian(at)cherne(dot)net
*/
(function ($) { $.fn.hoverIntent = function (f, g) { var cfg = { sensitivity: 7, interval: 100, timeout: 0 }; cfg = $.extend(cfg, g ? { over: f, out: g} : f); var cX, cY, pX, pY; var track = function (ev) { cX = ev.pageX; cY = ev.pageY }; var compare = function (ev, ob) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); if ((Math.abs(pX - cX) + Math.abs(pY - cY)) < cfg.sensitivity) { $(ob).unbind("mousemove", track); ob.hoverIntent_s = 1; return cfg.over.apply(ob, [ev]) } else { pX = cX; pY = cY; ob.hoverIntent_t = setTimeout(function () { compare(ev, ob) }, cfg.interval) } }; var delay = function (ev, ob) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); ob.hoverIntent_s = 0; return cfg.out.apply(ob, [ev]) }; var handleHover = function (e) { var ev = jQuery.extend({}, e); var ob = this; if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t) } if (e.type == "mouseenter") { pX = ev.pageX; pY = ev.pageY; $(ob).bind("mousemove", track); if (ob.hoverIntent_s != 1) { ob.hoverIntent_t = setTimeout(function () { compare(ev, ob) }, cfg.interval) } } else { $(ob).unbind("mousemove", track); if (ob.hoverIntent_s == 1) { ob.hoverIntent_t = setTimeout(function () { delay(ev, ob) }, cfg.timeout) } } }; return this.bind('mouseenter', handleHover).bind('mouseleave', handleHover) } })(jQuery);



