﻿/// <reference path="jquery-1.3.2.js" />

 function tooltip() {

    xOffset = 50;
    yOffset = -28;
    $(".twitteritem").hover(function(e) {        
        this.t = this.title;
        this.title = "";
        $("body").append("<p id='tooltip'>" + this.t + "</p>");

        $("#tooltip")
			.css("top", (e.pageY - xOffset) + "px")
			.css("left", (e.pageX + yOffset) + "px")
			.fadeIn("fast");

    },
	function() {
	    this.title = this.t;
	    $("#tooltip").remove();
	});
    $(".twitteritem").mousemove(function(e) {
        $("#tooltip")
			.css("top", (e.pageY - xOffset) + "px")
			.css("left", (e.pageX + yOffset) + "px");
    });
}
    

if ( window.addEventListener ) {    
    var kkeys = [], 
    konami = "38,38,40,40,37,39,37,39,66,65";
    window.addEventListener("keydown", function(e) {        
        kkeys.push(e.keyCode);
        if (kkeys.toString().indexOf(konami) >= 0) {                        
            $('#Konami').fadeIn(2000).fadeOut(3000);
            kkeys = [];
        }
    }, true);
}

function AddBlogComment(blogId, blogTitle) {
    $('#BlogId').val(blogId);
    $('#BlogCommentBlogTitle').html(blogTitle);
    $(".colorbox").colorbox({ opacity: 0.4, open: true, initialWidth: "550px", initialHeight: "450px;",
        width: "550px", height: "450px;", inline: true, href: "#divContent", overlayClose: false, close: ""
    });
}


function clearCommentsFormDefaultValues() {   
    if ($('#BlogCommentFullName').val() == "Name") {  $('#BlogCommentFullName').val('') ; }
    if ($('#BlogCommentEmailAddress').val() == "Email") { $('#BlogCommentEmailAddress').val('') };
    if ($('#BlogCommentText').val() == "Comment") { $('#BlogCommentText').val('') };
}

function restoreCommentsFormDefaultValues(){
    if ($('#BlogCommentFullName').val() == "") $('#BlogCommentFullName').val('Name');
    if ($('#BlogCommentEmailAddress').val() == "") $('#BlogCommentEmailAddress').val('Email');
    if ($('#BlogCommentText').val() == "") $('#BlogCommentText').val('Comment');
}

function resetCommentsFormDefaultValues(){
    $('#BlogCommentFullName').val('Name');
    $('#BlogCommentEmailAddress').val('Email');
    $('#BlogCommentText').val('Comment');
}

$(document).ready(function() {

tooltip();

    $('#ArticleDropDown').change(function() {
        document.location = $('#ArticleDropDown').val();
    });

    $('#PageDropDown').change(function() {
        document.location = $('#PageDropDown').val();
    });

    $('#StaffDropDown').change(function() {
        document.location = $('#StaffDropDown').val();
    });
    
    $('#BlogDropDown').change(function() {
        document.location = $('#BlogDropDown').val();
    });

    $('#AddCommentAjax').click(function() {

        clearCommentsFormDefaultValues();
        if (!$('#CommentForm').valid()) {
            restoreCommentsFormDefaultValues();
            return false;
        }

        var PostData = $('#CommentForm').serialize();
        $.getJSON(
            "/Blog/AddComment", PostData,
            function(comment) {
                var DivName = "NewBlogComments" + comment.BlogId;
                var CommentContainerName = "CommentContainer" + comment.BlogId;
                $("#" + DivName)
                    .append('<div class="newBlogComments"><!-- --></div>')
                    .append('<span class="CommentName">' + comment.BlogCommentFullName + ' wrote: </span>')
                    .append('<span class="CommentText">' + comment.BlogCommentText + '</span><br />')
                    .append('<div class="CommentDateLast">at ' + comment.BlogCommentDate + '</div>');
                $("#" + CommentContainerName).show();
            });
        $(".colorbox").colorbox.close();
        resetCommentsFormDefaultValues();
    });

    $('#AddCommentCloseBtn').click(function() {
        $(".colorbox").colorbox.close();
    });


    $('#MapZoomInLink').click(function() {
        $('#ImgZoomedIn').animate({ opacity: 0 }, 1);
        $('#ImgZoomedIn').animate({
            width: "700px",
            height: "422px",
            opacity: 1,
            top: "0px",
            left: "0px"}, 1500);
    });


 
    $('#ImgZoomedIn').click(function() {
    $('#ImgZoomedIn').animate({
        width: "0px",
        height: "0px",
        opacity: 0,
        top: "272px",
        left: "357px"}, 1500);
    });

    //old: 376, 48, 35
    //new:   357, 232, 35

    $('#MapZoomInLinkUK').click(function() {
        $('#ImgZoomedInUK').animate({ opacity: 0 }, 1);
        $('#ImgZoomedInUK').animate({
            width: "700px",
            height: "422px",
            opacity: 1,
            top: "0px",
            left: "0px"
        }, 1500);
    });

    $('#ImgZoomedInUK').click(function() {
        $('#ImgZoomedInUK').animate({
            width: "0px",
            height: "0px",
            opacity: 0,
            top: "230px",
            left: "500px"
        }, 1500);
    });

});
