﻿
var messagePointer;
var m_imageOffset = new ImageOffset();

$(document).ready(function() {
    /*
    jQuery.each(jQuery.browser, function(i) {
    if ($.browser.mozilla) {
    $("body").css("font-family", "arial");
    } else {
    $("body").css("font-family", "Century Gothic");
    }
    });
    */

    $("#PopupDetails").hide();
    $("#PopupDetails img").hide();

    $("div#PortfolioMenu ul li a").mouseover(function(event) {
        $(this).addClass("PortfolioMenuHove");
    });
    $("div#PortfolioMenu ul li a").mouseout(function(event) {
        $(this).removeClass("PortfolioMenuHove");
    });

    $("#FavoritesContainer img").mouseover(function(event) {
        var title = $(this).attr("category") + " > " + $(this).attr("alt") + " / " + $(this).attr("year")
        $("#PopupDetails h2").html(title).css("background-color", $(this).attr("catcolor"));
        $("#PopupDetails #PopupDetailsDimentions").html($(this).attr("dimentions"));
        $("#PopupDetails #PopupDetailsDescription").html($(this).attr("description"));
        $("#PopupDetails img[src=" + $(this).attr("src") + "]").show();

        //Set widht and height offset in order to position the floating popup to the top, bottom, right or left of the image.
        var imageIndex = $("#FavoritesContainer img").index(this);
        var imageWidth = $("#PopupDetails").width();
        var imageHeight = $("#PopupDetails").height();
        if (imageIndex <= 1) {
            //top left
            m_imageOffset.X = 20;
            m_imageOffset.Y = 0;
        }
        else if (imageIndex > 1 && imageIndex <= 3) {
            //top right
            m_imageOffset.X = 0 - (imageWidth + 20);
            m_imageOffset.Y = 0;
        }
        else if (imageIndex > 3 && imageIndex <= 5) {
            //bottom left
            m_imageOffset.X = 20;
            m_imageOffset.Y = 0 - (imageHeight / 2);
        }
        else {
            //bottom right
            m_imageOffset.X = 0 - (imageWidth + 20);
            m_imageOffset.Y = 0 - (imageHeight / 2);
        }

        $("#PopupDetails").show();
    });

    $("#FavoritesContainer img").mouseout(function(event) {
        $("#PopupDetails img").hide();
        $("#PopupDetails").hide();
    });

    $("#FavoritesContainer img").mousemove(function(event) {
        var width = $("#PopupDetails").width() / 2;
        $("#PopupDetails").css("left", event.clientX + m_imageOffset.X).css("top", event.clientY + m_imageOffset.Y);
    });

    // Email Events

    $("#SendEmailToRotem").click(function(e) {
        ShowMailForm("Send to Rotem", "Your name", "Your email", 1);
    });

    $("#SendEmailToFriend").click(function(e) {
        ShowMailForm("Send to a friend", "Your Name", "Friend's email", "2");
    });

    $("img[alt='Close Email Form']").click(function(e) {
        HideMailForm()
    });

    $("#EmailCancelation").click(function(e) {
        HideMailForm()
    });

    if (hideMessage == "True") {
        HideMessage();
    }
});

function ShowMailForm(sTitle, sNameTitle, sEmailTitle, iMailMode) {
    
    $("label[for='txtMailToName']").html(sNameTitle);
    $("label[for='txtMailToEmail']").html(sEmailTitle);
    $("#MailTo h2").html(sTitle);
    $("#MailTo").show();
    $("#hiddenMailMode").attr("value", iMailMode);
}

function HideMailForm() {
    $("#MailTo").hide();
}

function HideMessage() {
    messagePointer = setTimeout(" $('#ErrorMessage').fadeOut('normal'); clearInterval(messagePointer);", 3000);
}

function ImageOffset() {
    this.X = 0;
    this.Y = 0;
}


