﻿$(document).ready(function () {
    common.init();
});

var Common = function () { };

Common.prototype.init = function () {
    var height = $(window).height();
    $("body").height(height); 
    console.log(height);
    this.fixOpacityIssues();
    this.initEvents();
}

Common.prototype.fixOpacityIssues = function () {
    this.fixSmallIconOpacity();
    this.fixTinyIconOpacity();
    this.fixTextBubbleOpacity();
    this.fixPortfolioBubbleOpacity();
}

Common.prototype.fixSmallIconOpacity = function () {
    var count = 1;
    var self = this;
    $("div.smallIcon").each(function () {
        $("body").append("<div id='smallIconBackgroundFix" + count + "' class='smallIconBackgroundFix'></div>");
        var tempIcon = $("div#smallIconBackgroundFix" + count);
        var hasVScroll = $("body").height() > $(window).height();
        var scrollerOffset = self.getScrollerOffset(9);
        var offset = $(this).offset();
        $(tempIcon).css("top", offset.top + "px");
        $(tempIcon).css("left", offset.left + scrollerOffset + "px");
        $(tempIcon).addClass("smallIcon" + count);
        count++;
    });
}

Common.prototype.fixTinyIconOpacity = function () {
    var count = 1;
    var self = this;
    $("div.tinyIcon").each(function () {
        $("body").append("<div id='tinyIconBackgroundFix" + count + "' class='tinyIconBackgroundFix'></div>");
        var tempIcon = $("div#tinyIconBackgroundFix" + count);
        var scrollerOffset = self.getScrollerOffset(8);
        var offset = $(this).offset();
        $(tempIcon).css("top", offset.top + "px");
        $(tempIcon).css("left", offset.left + scrollerOffset + "px");
        $(tempIcon).addClass("tinyIcon" + count);
        count++;
    });
}

Common.prototype.fixTextBubbleOpacity = function () {
    var count = 0;
    var self = this;
    $("div.textBubble").each(function () {        
        $("body").append("<div id='textBubbleBackgroundFix" + count + "' class='textBubbleBackgroundFix'></div>");
        var backgroundBubble = $("div#textBubbleBackgroundFix" + count);
        var offset = $(this).offset();        
        var scrollerOffset = self.getScrollerOffset(8);
        $(backgroundBubble).css("height", $(this).height() + "px");
        $(backgroundBubble).css("width", Math.ceil($(this).width()) + 1 + "px");
        $(backgroundBubble).css("top", offset.top + "px");
        $(backgroundBubble).css("left", Math.floor(offset.left) + scrollerOffset +"px");        
        $(backgroundBubble).html($(this).html());
        count++;
        
    });
}

Common.prototype.fixPortfolioBubbleOpacity = function () {
    var count = 0;
    var self = this;
    $("div.portfolioBubble").each(function () {
        $("body").append("<div id='portfolioBubbleFix" + count + "' class='portfolioBubbleFix'></div>");
        var backgroundBubble = $("div#portfolioBubbleFix" + count);
        var offset = $(this).offset();


        var scrollerOffset = self.getScrollerOffset(8);

        $(backgroundBubble).css("height", $(this).height() + "px");
        $(backgroundBubble).css("width", Math.ceil($(this).width()) + 1 + "px");
        $(backgroundBubble).css("top", offset.top + "px");
        $(backgroundBubble).css("left", Math.floor(offset.left) + scrollerOffset + "px");
        $(backgroundBubble).html($(this).html());
        count++;

    });
    
}

Common.prototype.getScrollerOffset = function (offsetAmount) {
    var hasVScroll = $("body").height() > $(window).height();
    var scrollerOffset = 0;
    if (hasVScroll) {
        scrollerOffset = offsetAmount;
    }
    //console.log(scrollerOffset);
    //alert(scrollerOffset);
    return scrollerOffset;
}

Common.prototype.initEvents = function () {
    $("div.smallIconBackgroundFix").bind("mouseover", function () {
        $(this).css("background-color", "#fff");           
        $(this).parent()
    });

    $("div.smallIconBackgroundFix").bind("mouseout", function () {
        $(this).css("background-color", "#F6FBF0");        
    });

}

var common = new Common();
