﻿
// Background-image
$(function() {
    $.fn.supersized.options = {
        startwidth: 1024,
        startheight: 768,
        vertical_center: 1,
        slideshow: 1,
        navigation: 1,
        transition: 1, //0-None, 1-Fade, 2-slide top, 3-slide right, 4-slide bottom, 5-slide left
        pause_hover: 0,
        slide_counter: 0,
        slide_captions: 0,
        slide_interval: 60000
    };
    $('#supersize').supersized();
});



var showContent = true;

$(document).ready(function() {



	//$("#googleMapsOverlay").css({ height: $(window).height() - 66 });

	//$("#theMap").css({ width: $(window).width() + 381 });
	//$("#theMap").css({ height: $(window).height() - 124 + 54});
	//$("#theMap").css({ top: -54});

//	$('#theMap').css({ width: $(window).width() + 381 });
	//document.getElementById('theMap').src = document.getElementById('theMap').src;
	//setTimeout('$("#googleMapsOverlay").hide()', 2000);

	setTimeout('$("#btn-ShowMap").fadeIn(300)', 1000);

		

    var h = $(".search_inner_1");

    $(".search").css("height", h.height());

    // Load tweets through ajax
    $(".twitter-items").load("twittersearch.aspx?menu=" + currentMenu, ActivateScrollingOnTweets);

	//alert("g_map.aspx?menu=" + currentMenu + "%26id=" + currentId);

	$("#googleMapsOverlay").load("g_map.aspx?menu=" + currentMenu + "&amp;id=" + currentId);

    // Show hide twitter-box
    $(".twitter-tab").bind("click", function(e) {
        if ($("#twitter-area").css("height") == '0px') {

			$(".footer-area").css("margin-top", "2");

            $("#twitter-area").animate({ height: '94' }, 1500);

            setTimeout('$("#twitter-arrow-left").fadeIn(300)', 1200);
            setTimeout('$("#twitter-arrow-right").fadeIn(300)', 1200);

            createCookie("hideTwitter", false, 1);

        }
        else {

            $("#twitter-arrow-left").fadeOut(300);
            $("#twitter-arrow-right").fadeOut(300);

            $("#twitter-area").animate({ height: '0' }, 1500, function() { $(".footer-area").css("margin-top", "0"); })

            createCookie("hideTwitter", true, 1);

        }
    });

	




    // Button to show map
    $("#btn-ShowMap").bind("click", function(e) {

		//alert($("#theMap").css("height"));

        if ($("#content").css("display") == "none" && $("#googleMapsOverlay").css("display") == "block") {

            $("#btn-hide").css("display", "block");

            $("#btn-ShowContent").fadeOut("slow");


			

			$('#googleMapsOverlay').hide();


            // if content is hidden, show it
            if ($("#content").css("display") == "none") {
                setTimeout('$("#content").show("slide", { direction: "down" }, 300)', 100);
            }

            setTimeout('$("#menu-top ul li ul").fadeIn(1000)', 800);

            setTimeout('$("#navigation").fadeIn(1000)', 800);
            setTimeout('$("#supersize_outer").fadeIn(1000)', 800);

            setTimeout('$("html#html_id").css("overflow-y", "auto")', 900);
            setTimeout('$("html#html_id").css("overflow-x", "none")', 900);
        }

        else {

			$('#googleMapsOverlay').hide();

            if ($(window).height() < Number($("#content_inner").height()) + 250) {
                $("html#html_id").css("overflow-y", "scroll");
            }

            $("#menu-top ul li ul").fadeOut("slow");

            $("#supersize_outer").hide();
            $("#navigation").hide();


            // if content is not hidden, hide it
            if ($("#content").css("display") == "block") {
                setTimeout('$("#content").hide("slide", { direction: "down" }, 300)', 100);
            }

			setTimeout('$("#googleMapsOverlay").fadeIn(1000)', 800);
			setTimeout('$("#btn-ShowContent").fadeIn(1000)', 800);

        }

    });

    // Hide content button
    $("#btn-hide").bind("click", function(e) {
        hideContent();
    });

	$("#btn-hide-img").hover(function() {
		this.src = "../images/btn_hide_bover.png";
	}, function() {
		this.src = "../images/btn_hide.png";
	});

	

    // Show content button
    $("#btn-ShowContent").bind("click", function(e) {
        showTheContent();
    });

	$("#btn-ShowContent-img").hover(function() {
		this.src = "../images/btn_show_hover.png";
	}, function() {
		this.src = "../images/btn_show.png";
	});



    // Next search result
    $(".search_next").bind("click", function(e) {

        var id = $(this).attr("id");

        var idSub = parseInt(id.substring(id.length - 1, id.length));

        //var thisId = document.getElementById("#search_inner_" + idSub);

        //var currentslide2 = $('.search_inner_1');

        $('.search_inner_' + idSub).hide();
        $('.search_inner_' + (idSub + 1)).show();


        var h = $(".search_inner_"  + (idSub + 1));


        $(".search").css("height", h.height());

        //alert("search_inner_" + idSub);

        //var nextId = document.getElementById("search_inner_" + (idSub + 1));

        //$("search_inner_" + (idSub + 1)).css({ display: 'block' });

        //$(".search").css("height", "");
        //$(".search").css("overflow", "visible");



    });

    // previous search result
    $(".search_pre").bind("click", function(e) {

        var id = $(this).attr("id");

        var idSub = parseInt(id.substring(id.length - 1, id.length));

        //var thisId = document.getElementById("search_inner_" + idSub);

        //$(thisId).css({ display: 'none' });

        //var preId = document.getElementById("search_inner_" + (idSub - 1));

        //$(preId).css({ display: 'block' });

        $('.search_inner_' + idSub).hide();
        $('.search_inner_' + (idSub - 1)).show();

        //$(".search").css("overflow", "visible");


        var h = $(".search_inner_" + (idSub - 1));
        $(".search").css("height", h.height());

    });

    $('.showThisImage').click(function() {

        if (!$('#doc_slideshow .doc_activeslide').hasClass($(this).attr("id"))) {
            var currentslide = $('#doc_slideshow .doc_activeslide');
            currentslide.removeClass('doc_activeslide');

            var imageSelected = "." + $(this).attr("id");
            $(imageSelected).hide().addClass('doc_activeslide');

            $('.showThisImage').removeClass('showThisImageActive');
            $(this).addClass('showThisImageActive');

            currentslide.fadeOut(750);
            $(imageSelected).fadeIn(750);


            var nextSlideNum = 0;

			// if slide number is bigger than 9
			if($(this).attr("id").length == 8)
			{
				nextSlideNum = $(this).attr("id").substring($(this).attr("id").length - 2, $(this).attr("id").length);
			}
			else
			{
				nextSlideNum = $(this).attr("id").substring($(this).attr("id").length - 1, $(this).attr("id").length);
			}

            var nextSlideLink = "#imgNum" + nextSlideNum;

            $('.showThisImage').removeClass('showThisImageActive');
            $(nextSlideLink).addClass('showThisImageActive');

            var nextImgSlideLink = "#imgLinkNum" + nextSlideNum;

            $('.img_slide_link').removeClass('active_slide_link');
            $(nextImgSlideLink).addClass('active_slide_link');

            $('.img_slide_link').show();
            $(nextImgSlideLink).hide();

        }
    });

    $('.showThisImage').hover(function() {
        if (!$(this).hasClass('showThisImageActive')) {
            $('.img_slide_link', this).hide();
        }
    }, function() {
        if (!$(this).hasClass('showThisImageActive')) {
            $('.img_slide_link', this).show();
        }
    });





});

$(window).bind("load", function() {


    // Cookie is set to hide twitter
    if (readCookie("hideTwitter") == "true") {
        $("#twitter-arrow-left").css( "display", "none" );
        $("#twitter-arrow-right").css( "display", "none" );
        $("#twitter-area").css("height", "0px");

    }
    else {
        $('#twitter-arrow-left').css( "display", "block" );
        $('#twitter-arrow-right').css( "display", "block" );
    }


    var embedHeight = $('.video object embed').height();
    var embedWidth = $('.video object embed').width();




    // safari fix
    if (embedHeight == "0" || embedHeight == null) {

        embedHeight = $('.video object').height();

        // ie7 fix
        if (embedHeight == null) {
            embedHeight = $('embed').height();
        }
    }


    // safari fix
    if (embedWidth == "0" || embedWidth == null) {

        embedWidth = $('.video object').width();

        // ie7 fix
        if (embedWidth == null) {
            embedWidth = $('embed').width();

        }
    }





    embedHeight = embedHeight + "px";
    embedWidth = embedWidth + "px";




    $('.video').css({ "height": embedHeight });
    $('.video').css({ "width": embedWidth });



    //$('.video_outer').css({ height: embedHeight });
    //$('.video_outer').css({ width: embedWidth });

    //$('#loading').hide();
    //$('#supersize').fadeIn(1000);
    $('#navigation').fadeIn(1000);

    //$('#loading_flash').hide();



    

	//   
	//setTimeout('refreshMap()', 1500);
	//



});

$(window).bind("resize", function() {
	$("#theMap").css({ width: $(window).width() + 381 });
	$("#theMap").css({ height: $(window).height() - 124 + 54});
});

//function refreshMap() {

    //if ($("#googleMapsOverlay").css("display") == "none") {

        //$("#googleMapsOverlay").show();

        //AttachMap();

        //$("#googleMapsOverlay").hide();
    //}
    //else {
        //AttachMap();
    //}

//}

function hideContent() {

    if ($(window).height() < Number($("#content_inner").height()) + 250) {
        $("html#html_id").css("overflow-y", "scroll");
    }

    $("#content").hide("slide", { direction: "down" }, 500);
    $("#btn-ShowContent").fadeIn("slow");
    $("#menu-top ul li ul").hide();
    $("#btn-hide").hide();
}

function showTheContent() {
    setTimeout('$("#btn-hide").show()', 500);
    $("#content").show("slide", { direction: "down" }, 500);
    $("#btn-ShowContent").fadeOut("slow");
    $("#menu-top ul li ul").show();
    setTimeout('$("html#html_id").css("overflow-y", "auto")', 900);
}

function screensaver() {

    if ($("#content").css("display") == "block") {
        
        if ($(window).height() < Number($("#content_inner").height())) {
            $("html#html_id").css("overflow-y", "scroll");
        }

        $("#content").hide("slide", { direction: "down" }, 500);
        //$("#btn-ShowContent").fadeIn("slow");
        //$("#menu-top ul li ul").fadeOut("slow");

        showContent = false;
    }
    //else {
        //alert("what");
    //}
}

function ActivateScrollingOnTweets() {
    // Scrolling for tweets
    $('#twitter-area').serialScroll({
        items: '.twitter-item',
        prev: '#twitter-arrow-left',
        next: '#twitter-arrow-right',
        start: 0, //as we are centering it, start at the 1st
        duration: 2000,
        force: true,
        stop: true,
        lock: false,
        cycle: true, //pull back once you reach the end
        easing: 'easeOutQuart', //use this easing equation for a funny effect
        jump: false //click on the images to scroll to them
    });
}






// Hide twitter cookie

function createCookie(name, value, days) {

    var expires = "";

    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        expires = "; expires=" + date.toGMTString();
        document.cookie = name + "=" + value + expires + "; path=/";
    }
    else {
        expires = "";
        document.cookie = name + "=" + value + expires + "; path=/";
    }
}


function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name, "", -1);
}

function addOverlay() {
	
      
}


function doc_nextslide() {
    
    var currentslide = $('#doc_slideshow .doc_activeslide');
    
    currentslide.removeClass('doc_activeslide');

    var nextslide = currentslide.next().length ? currentslide.next() : $('#doc_slideshow a:first');

    nextslide.addClass('doc_activeslide');
    
    currentslide.fadeOut(750);
    nextslide.fadeIn(750);

    $(nextslide).addClass('doc_activeslide');
    //$(nextslide).removeClass('doc_nextslide');

    //$(nextSlideLink).addClass('doc_nextslide');

	var currentSlideNum = 0;
	var nextSlideNum = 0;

	// if slide number is bigger than 9
	if(currentslide.attr("id").length == 6)
	{
		currentSlideNum = currentslide.attr("id").substring(currentslide.attr("id").length - 2, currentslide.attr("id").length);
	}
	else
	{
		currentSlideNum = currentslide.attr("id").substring(currentslide.attr("id").length - 1, currentslide.attr("id").length);
	}

	//alert(nextSlideNum.attr("id").length);

	// if slide number is bigger than 9
	if(nextslide.attr("id").length == 6)
	{
		nextSlideNum = nextslide.attr("id").substring(nextslide.attr("id").length - 2, nextslide.attr("id").length);
	}
	else
	{
		nextSlideNum = nextslide.attr("id").substring(nextslide.attr("id").length - 1, nextslide.attr("id").length);
	}

    
    

    var nextSlideLink = "#imgNum" + nextSlideNum;

    $('.showThisImage').removeClass('showThisImageActive');
    $(nextSlideLink).addClass('showThisImageActive');

    var nextImgSlideLink = "#imgLinkNum" + nextSlideNum;

    $('.img_slide_link').removeClass('active_slide_link');
    $(nextImgSlideLink).addClass('active_slide_link');

    $('.img_slide_link').show();
    $(nextImgSlideLink).hide();
    
}




