﻿// Namespaces
Chunk = {};
Chunk.Sharing = {};

Chunk.Sharing.Share = function(url, title) {
    var width = 626; // Facebook recommendation
    var height = 436; // Facebook recommendation

    var options = 'toolbar=0, status=0, width=' + width + ', height=' + height;
    var shareUrl = 'http://www.facebook.com/sharer.php?u=' + encodeURIComponent(url) + '&t=' + encodeURIComponent(title);

    window.open(shareUrl, 'sharer', options);
    return false;
}

// There is a conflict between the stylish select .js and jquery tabs
// jQuery tabs uses $.inArray() which uses Array.prototype.indexOf (if its defined, not sure why they are doing this...as its a bit dangerous)
// "stylish select" has an incompatible implementation of indexOf and causes jQuery tabs to choke in IE.
// So, we can use these functions to temporaily remove the reference to indexOf - which causes jQuery to fallback and use a for each loop in $.inArray()

Chunk._ArrayIndexOfTempStorage = null;
Chunk.RemoveIndexOfReference = function() {
    Chunk._ArrayIndexOfTempStorage = Array.prototype.indexOf;
    Array.prototype.indexOf = null;
}

Chunk.RevertIndexOfReference = function() {
    Array.prototype.indexOf = Chunk._ArrayIndexOfTempStorage;
}

Chunk.IsInFrame = function() {
    return (window.location != window.parent.location);
}

Chunk.BustOutOfFrame = function() {
    window.parent.location = window.location;
}

// jQuery helper
$.postJSON = function(url, data, callback) {
    $.post(url, data, callback, "json");
};

Chunk.ResizeShadowBox = function(jqObject) {
    if (jqObject == null || jqObject.length == 0)
        return;

    var v = function(element, css) {
        return Math.max( 0, parseInt(element.css(css)) || 0 );   // Performing a Math.max here as Chrome was reporting negative margins for som reason         
    }

    var e = jqObject;
    var width = v(e, "width") + v(e, "padding-left") + v(e, "padding-right") + v(e, "margin-left") + v(e, "margin-right");
    var height = v(e, "height") + v(e, "padding-top") + v(e, "padding-bottom") + v(e, "margin-top") + v(e, "margin-bottom");

    var player = parent.Shadowbox.player;
    player.height = height;
    player.width = width;

    parent.Shadowbox.skin.onWindowResize();
}

