﻿$(document).ready(function() {
    $('#TopBar').corner('15px');
    var curDate = new Date();
    getCalendar(curDate.getMonth(), curDate.getFullYear());
    //loadContent("/Bowring/Content/HomePage.htm");
    $('#Content').load("/Bowring/Content/HomePage.htm");
    $('#ContentBlock').attr("style", "width:" + (parseInt(GetWidth())-525) + "px;");
}
);

function loadContent(url) {
    $('#historyController').attr('src', url);
}

var tempFnPtr = null;
function loadPage() {
    $('#Content').html(document.getElementById('historyController').contentWindow.document.body.innerHTML);
    $('#imageFrame').corner('sculpt br bl').corner('round top');
    //$('#imageFrame').corner('round');
    /*$('#imageFader').innerfade({ 
    animationtype:'slide',
    speed: 'slow',
    timeout: '5000'
    });*/
    //$.fn.cycle.defaults = { after: function(currSlideElement, nextSlideElement, options, forwardFlag) { alert('Yo ' + currSlideElement); return true; } };
    
    //$('#imageFader').cycle('fade');
    $('#imageFader').cycle( { fx:      'fade', 
                                speedIn:  2500, 
                                speedOut: 500,
                                //timeoutFn: function(currSlideElement, nextSlideElement, options, forwardFlag) { $('#imageDesc').text(currSlideElement.title);  }
                                before : function(currSlideElement, nextSlideElement, options, forwardFlag) { $('#imageDesc').text(nextSlideElement.title); }
                            });
    
    if(tempFnPtr != null) {
        //alert(tempFnPtr);
        //eval (tempFnPtr);
        
        }
}

function fixPageTitle(obj) {
    $('#Content').html("Loading...");
    if (obj.innerHTML.indexOf("Home") == -1 
            && obj.innerHTML.indexOf("Newsletters") == -1 
            && obj.innerHTML.indexOf("History") == -1 
            && obj.innerHTML.indexOf("NewsletterArchive") == -1 
            && obj.innerHTML.indexOf("Member") == -1) {
        $('#EventCalendarContainer').hide();
        //$('#EventCalendarContainer').attr("width", "2px");
        $('#ContentBlock').attr("style", "width:" + (parseInt(GetWidth())-300) + "px;");
    }
    else {
        $('#EventCalendarContainer').show();
        var curDate = new Date();
        getCalendar(curDate.getMonth(), curDate.getFullYear());
        //$('#EventCalendarContainer').attr("width", "2px");
        $('#ContentBlock').attr("style", "width:" + (parseInt(GetWidth())-525) + "px;");
    }
    //alert(obj.textContent);
    if(obj.textContent != null)
        document.title = "Bowring Institute - " + obj.textContent;
    else
        document.title = "Bowring Institute - " + obj.innerText;
    
    //alert(obj.attr('rel'));
    //alert(obj.attributes.getNamedItem("rel").nodeValue);
    if(obj.attributes.getNamedItem("rel").nodeValue != null && obj.attributes.getNamedItem("rel").nodeValue != "")
        tempFnPtr = obj.attributes.getNamedItem("rel").nodeValue + "();";
    else
        tempFnPtr = null;
}


//****************************************************************************************
//
//                           CODE FOR THE EVENT CALENDAR
//
//****************************************************************************************
$(document).ajaxError(function(event, request, settings) {
    $('#EventList').html("Error requesting page " + settings.url);
});

function getCalendar(month, year) {
    if (month == -1) {
        month = 11;
        year--;
    }
    else if (month == 12) {
        month = 0;
        year++;
    }

    var cal = new Calendar(month, year);
    cal.generateHTML();
    var str = cal.getHTML();
    $('#Calendar').hide('fast');
    $('#Calendar').html(str);

    $('#EventList').html(" ");
    $('#Calendar').show('slow', function() {
        //$.getJSON("/Bowring/Content/Calendar.asp?&Month=" + month + "&Year=" + year, function(json) {
        $.getJSON("/Bowring/Content/Calendar.aspx?&Month=" + month + "&Year=" + year, function(json) {
            //alert(json.Events);
            if (json.Events != 'null') {
                for (var i = 0; i < json.Events.length; i++) {

                    $('#' + json.Events[i].Day).addClass("calendar-event").css("color", "white").css("font-size", "smaller");

                    var eventDay = new Date(year, month, $('#' + json.Events[i].Day).text());
                    //$('#EventList').append("<fieldset><legend><b>" + cal_days_labels[eventDay.getDay()] + " " + $('#' + json.Events[i].Day).text() + "</b><legend>" + json.Events[i].Event + ". " + json.Events[i].Description + "</fieldset>");
                    $('#EventList').append("<fieldset><legend><b>" + cal_days_labels[eventDay.getDay()] + " " + $('#' + json.Events[i].Day).text() + "</b></legend><span>" + json.Events[i].Event.replace("<br>", " ") + ". " + json.Events[i].Description.replace("<br>", " ") + "</span></fieldset>");
                }
                $('.calendar-event').corner('5px');
            }
            else
                $('#EventList').html("<i>Events not updated for the month</i>");
        });
    });
}

function Sports() {
    alert('Yo');
    $("ul.gallery").prettyGallery({
		    itemsPerPage : 2,
		    animationSpeed : 'normal', /* fast/normal/slow */
		    navigation : 'top',  /* top/bottom/both */
		    of_label: ' of ', /* The content in the page "1 of 2" */
		    previous_title_label: 'Previous page', /* The title of the previous link */
		    next_title_label: 'Next page', /* The title of the next link */
		    previous_label: 'Previous', /* The content of the previous link */
		    next_label: 'Next' /* The content of the next link */
	    });       
}


var l = new Image();
l.src = "/Bowring/Images/loading.gif";
function test(image, text)
{
	//alert('Loaded');
	Fimage.src = image;
	Fimage.title = "";
	Fimage.title = text;									
}
function showData(image, text)
{
	Fimage.src = "/Bowring/Images/loading.gif";
	var i = new Image();
	i.src = image;
	Fimage.title = "Loading...";
	i.onload = function () {test(image, text);}
	//Fimage.src = image;
	FText.innerHTML = text;
	/*FF.style = "background-image:" + image;*/
	//alert(FF.background);
	//FF.background = '#ffffff url(' + image + ') no-repeat fixed center center';
	//FF.style = "'background-image:" + image + "'";
}


function GetWidth()
{
        var x = 0;
        if (self.innerHeight)
        {
                x = self.innerWidth;
        }
        else if (document.documentElement && document.documentElement.clientHeight)
        {
                x = document.documentElement.clientWidth;
        }
        else if (document.body)
        {
                x = document.body.clientWidth;
        }
        return x;
}


function GetHeight()
{
        var y = 0;
        if (self.innerHeight)
        {
                y = self.innerHeight;
        }
        else if (document.documentElement && document.documentElement.clientHeight)
        {
                y = document.documentElement.clientHeight;
        }
        else if (document.body)
        {
                y = document.body.clientHeight;
        }
        return y;
}