﻿/* Top Menu Drop Down scripts */

$(function() {
    $('.dropDownButton').click(function(event) {
        $('#' + event.target.id + 'Menu').slideToggle(200);
    });
});
$(function() {
    $('.dropDownClose').click(function(event) {
        $('#' + event.target.id.substring(0, event.target.id.length - 5) + 'Menu').slideToggle(200);
    });
});

/* Social Network Sharing */

$(function() {
    $('.shareButton').click(function(event) {
        var pageURL = window.location;
        var pageTitle = document.title;
        var selectedService = this.id;
        var gotoURL = '';

        if (selectedService == 'hiscShare_digg') {
            gotoURL = 'http://digg.com/submit?url=' + pageURL + '&title=' + pageTitle;
        }
        else if (selectedService == 'hiscShare_delicious') {
            gotoURL = 'http://del.icio.us/post?url=' + pageURL + '&title=' + pageTitle;

        }
        else if (selectedService == 'hiscShare_facebook') {
            gotoURL = 'http://www.facebook.com/share.php?u=' + pageURL;

        }
        else if (selectedService == 'hiscShare_myspace') {
            gotoURL = 'http://www.myspace.com/Modules/PostTo/Pages/?c=' + pageURL + '&t=' + pageTitle;

        }
        else if (selectedService == 'hiscShare_netscape') {
            gotoURL = 'http://www.netscape.com/submit/?T=' + pageURL + '&U=URL' + pageTitle;

        }
        else if (selectedService == 'hiscShare_reddit') {
            gotoURL = 'http://reddit.com/submit?url=' + pageURL + '&title=' + pageTitle

        }
        else if (selectedService == 'hiscShare_stumble') {
            gotoURL = 'http://www.stumbleupon.com/submit?url=' + pageURL + '&title=' + pageTitle;

        }
        //else if (selectedBookmark == 'yahoo') {
        //gotoURL='http://myweb2.search.yahoo.com/myresults/bookmarklet?t='+pageTitle+'&u='+pageURL+'&ei=UTF-8';   
        //}	

        if (gotoURL != '') {
            window.open(gotoURL);
        }
    });
});

/* CHANGING STYLESHEETS */

stylesheetTitles = new Array("small", "large"); //stores all the stylesheet "titles" in ascending order
siteID = "hiscSeniorFoundation";

function increase()
{
	if (textsize < stylesheetTitles.length-1)
	{	
		textsize++; //increases counter
		var title = stylesheetTitles[textsize]; //gets the correct "title" of the stylesheet
		setActiveStyleSheet(title); //changes the stylesheet
	}
}

function decrease()
{
	if (textsize > 0)
	{
		textsize--; //decreases counter
		var title = stylesheetTitles[textsize]; //gets the correct "title" of the stylesheet
		setActiveStyleSheet(title); //changes the stylesheet
	}
}
	
function setActiveStyleSheet(title)
{
	var i, a, main;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) //cycles through all "link" elements
	{
    	if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) //checks to make sure you are looking at a stylesheet
		{
		    a.disabled = true; //disables all stylesheets
		    if (a.getAttribute("title") == title) {
		        a.disabled = false; //enables correct stylesheet by evaluating the "title"
		    }
     		createCookie(siteID + "_style", textsize, 365);
    	}
  	}}

/* SETTING COOKIES  */

function createCookie(name,value,days)
{
    if (days)
    {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else expires = "";
    var textsizeString = String(value); //converts "textsize" to a string
    document.cookie = name+"="+textsizeString+expires+"; path=/"; //writes the cookie
}

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;
}

/* textsize functions  */

var cookie = parseInt(readCookie(siteID+"_style")); //reads the cookie and extracts the preferred stylesheet's number
textsize = (cookie ? cookie : 0); //checks to see if a cookie exists and gives "textsize" the correct value

//setActiveStyleSheet(stylesheetTitles[textsize]); //sets the preferred stylesheet

$(function() {
    $('#smallerText').click(function(event) {
        decrease(); 
        $("#smallerText").attr('src','/Style%20Library/HISCFoundation/fontSizeSmallActive.gif');
        $("#largerText").attr('src','/Style%20Library/HISCFoundation/fontSizeLargeInactive.gif');
        return false;
    });
});
$(function() {
    $('#largerText').click(function(event) {
        increase(); 
        $("#smallerText").attr('src','/Style%20Library/HISCFoundation/fontSizeSmallInactive.gif');
        $("#largerText").attr('src','/Style%20Library/HISCFoundation/fontSizeLargeActive.gif'); 	 
        return false;
    });
});
   
if (textsize == 1) { 
    $("#smallerText").attr('src','/Style%20Library/HISCFoundation/fontSizeSmallInactive.gif');
    $("#largerText").attr('src','/Style%20Library/HISCFoundation/fontSizeLargeActive.gif');  
}
else {
    $("#smallerText").attr('src','/Style%20Library/HISCFoundation/fontSizeSmallActive.gif');
    $("#largerText").attr('src','/Style%20Library/HISCFoundation/fontSizeLargeInactive.gif');
}
// end textsize functions

