/* 
Code Highlighting 
Courtesy of Dean Edwards star-light 
http://dean.edwards.name/my/behaviors/#star-light.htc
    - with jQuery methods added, of course
*/
$(document).ready(function(){
/*    $("#nav li").hover(
        function(){ $("ul", this).fadeIn("slow"); }, 
        function() { } 
    );*/
    if (document.all) {
        $("#nav li").hoverClass ("over");
		$("#subnav ul li").hoverClass ("over");
		$("#subnav ul li ul li").hoverClass ("over");
    }
});

$.fn.hoverClass = function(c) {
    return this.each(function(){
        $(this).hover( 
            function() { $(this).addClass(c); },
            function() { $(this).removeClass(c); }
        );
    });
};

function playClip() {
	var links = document.getElementsByTagName('a');
	
	for (i=0;i<links.length;i++) {
        var link = links[i];
		
        if (( link.getAttribute ( 'href' ) ) && ( link.getAttribute ( 'rel' ) == 'clip' ) ) {
            link.onclick = function() {
                document.getElementById('videoPlayerSwf').playVideo(this.getAttribute('href'),this.name);
                window.scrollTo(0,70);
                return false;
        	}
		}
	}
}

function toggleQuestion() {
	var links = document.getElementsByTagName('a');
	
	for (i=0;i<links.length;i++) {
    
		var link = links[i];
        
		if (( link.getAttribute ( 'href' ) ) && ( link.getAttribute ( 'rel' ) == 'reveal' )) {
			link.onclick = function() {				
				this.style.backgroundPosition = 'center -23px';	
				this.setAttribute('rel','hide');
				this.nextSibling.style.display = 'block';
				toggleQuestion();
				return false;
			}
		}
		
		if (( link.getAttribute ( 'href' ) ) && ( link.getAttribute ( 'rel' ) == 'hide' )) {
			link.onclick = function() {
				this.style.backgroundPosition = 'center top';	
				this.setAttribute('rel','reveal');
				this.nextSibling.style.display = 'none';
				toggleQuestion();
				return false;
			}
		}
	}
}

function goArchive(){
  if(document.weeklyarchives.archive.value != '')
  	window.location='?view=archive&week='+document.weeklyarchives.archive.value;
}

function genericPop() {
		var links = document.getElementsByTagName('a');
	
	for (i=0;i<links.length;i++) {
        var link = links[i];
		
        if (( link.getAttribute ( 'href' ) ) && ( link.getAttribute ( 'rel' ) == 'popup' ) ) {
            link.onclick = function() {
				displayWindow(this.href,'popUp',800,600,'scrollbars=1');
                return false;
        	}
		}
		
		if (( link.getAttribute ( 'href' ) ) && ( link.getAttribute ( 'rel' ) == 'popupScroll' ) ) {
            link.onclick = function() {
				displayWindow(this.href,'popUp',800,600,'scrollbars=1');
                return false;
        	}
		}
	}
}

function wallpaperPop() {
	var links = document.getElementsByTagName('a');
	
	for (i=0;i<links.length;i++) {
        var link = links[i];
		
        if (( link.getAttribute ( 'href' ) ) && ( link.getAttribute ( 'rel' ) == 'wallpaper' ) ) {
            link.onclick = function() {
				displayWindow(this.href,'wallpaperPop',865,680,'scrollbars=1');
                return false;
        	}
		}
	}
}

function galleryPop() {
		var links = document.getElementsByTagName('a');
	
	for (i=0;i<links.length;i++) {
        var link = links[i];
		
        if (( link.getAttribute ( 'href' ) ) && ( link.getAttribute ( 'rel' ) == 'photogallery' ) ) {
            link.onclick = function() {
				displayWindow(this.href,'photoGalleryPop',484,550);
                return false;
        	}
		}
	}
}

addLoadEvent(playClip);
addLoadEvent(toggleQuestion);
addLoadEvent(genericPop);
addLoadEvent(wallpaperPop);
addLoadEvent(galleryPop);