﻿/* 
 * Simon Willison's addLoadEvent
 * 
 * The addLoadEvent function takes as an argument another function which should be executed once the page has loaded.
 * Unlike assigning directly to window.onload, the function adds the event in such a way 
 * that any previously added onload functions will be executed first.
 *
 * URL: http://simonwillison.net/2004/May/26/addLoadEvent/
 */


function addLoadEvent(func){
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
		window.onload = func;
		} else{
			window.onload = function(){
				oldonload();
				func();
				}			}
	}

/*
 * Author: Vladimir Solovey
 * Slide Show for Jquery
 *
 * Use JQuery 1.4 (jquery.js)
 *
 * URL: http://jquery.com/
 */

function startSlideShow(startFrame, endFrame, fadeSpeed, delayLength, isLoop) {
    $('.slideshow div:gt(0)').hide(); 
    setTimeout(function(){switchSlides(startFrame, startFrame, endFrame, fadeSpeed, delayLength, isLoop)}, delayLength);
}

function switchSlides(thisFrame, startFrame, endFrame, fadeSpeed, delayLength, isLoop) {  
    if(isLoop){
        $('#slideshow' + thisFrame).fadeOut(fadeSpeed);
        if (thisFrame == endFrame){ 
            thisFrame = startFrame; 
        } 
        else { 
            thisFrame = thisFrame + 1; 
        }
        $('#slideshow' + thisFrame).fadeIn(fadeSpeed);
    }
    else {
        $('#slideshow' + thisFrame).fadeOut(fadeSpeed);
        if (thisFrame != endFrame){
            thisFrame = thisFrame + 1;
            $('#slideshow' + thisFrame).fadeIn(fadeSpeed);
        } 
        else {
            return;
        }
    }
    setTimeout(function(){switchSlides(thisFrame, startFrame, endFrame, fadeSpeed, delayLength, isLoop)}, delayLength);    
}  

/*
 * Author: Vladimir Solovey
 * Visual Enhancements for JQuery 
 *
 * Use JQuery 1.3.2 (jquery.js)
 * Requires presence of 'collapse_switch' class, followed by the element with 'collapse' class
 *
 * URL: http://jquery.com/
 */
 
/*
 * Make sure 'collapse' class 'display' property is set to 'none' in CSS
 * This way page does not load all the collapsable divs into view before hiding them through $('.collapse').hide();
 */
 
function collapsePanels(){
    
    $('.collapse').hide()
    
	$('.collapse_switch').click(function(){
	$('.collapse').hide()
	  $('div[id*=' + this.rel + ']').slideToggle(500);
	  return false;
	})     
}