﻿var pos = {x:0, y:0, getPosition: function(){return this.x + 'px ' + this.y + 'px';}}

function init()
{
	
//	var elem =document.getElementById('g');
//	elem.onclick = test;
//	//alert(Math.floor(Math.random() * 100));
//	
//	pos.x = 16 * (Math.floor(100 * Math.random()));		
//	elem.style.backgroundPosition = pos.getPosition();
	
	//accordion();
	
	var socialMedia = document.getElementById('social-media');




	$('span', socialMedia)
	.fadeTo('fast', 0.5)
	.mouseout(
	    function() 
	    {
	        $(this)
	            .stop()
	            .fadeTo('slow', 0.5);
	    }
	)
	.mouseover(
	    function() {
	        $(this)
	            .stop()
	            .fadeTo('slow', 1);
	    }
	)
	
	
	
	
	if(window.screen.colorDepth && window.screen.colorDepth <= 24)
	{
	    $('body').css('background-image', 'none');
	    $('#side').css('background-color', '#000').css('background-image', 'none');
	    $('#mainmenu').css('background-image', 'none');
	}
	
	
	$('ul.sidemenu a.csshover')
	.filter(
	    function()
	    {
	        return !($(this).hasClass('current'));
	    }
	)	
	.css('background-color', '#666666')
	.mouseover(function(){
		$(this).stop().animate({backgroundColor:"#aaaaaa"}, {duration:200}).animate({backgroundColor:"#999999"}, {duration:200});
		})
	.mouseout(function(){
		$(this).stop().animate(
			{backgroundColor:"#666666"}, 
			{duration:700})
		})
	
	
	
	
	var elem = $("#homemenu").remove()[0];
	
	$('#banner').append(elem);	
	var home = $('#mainmenu').children()[0];	
	var homeLeftPos = findPos(home).left
	
	$(elem).hide().fadeOut(1);
	
	var mainmenu_TOP_MARGIN = 48;
	
	$(elem).css('top',$('#mainmenu').height() + mainmenu_TOP_MARGIN).css('margin-left', '-6px');
	
	
	
	$($('#search').children('input')[0]).val('Search')
	    .focus(function(){
                            if(this.value == 'Search')
                            {
                                this.value = '';
                                $(this).removeClass('waiting');
	                            $(this).addClass('using');
                            }
	
	                    })
	    .blur(function(){
	                        if(this.value.length == 0)
	                        {
	                            this.value = 'Search';
	                            $(this).removeClass('using');
	                            $(this).addClass('waiting');
	                        }
	                })
	
	$(home).toggle(
	                function(){$(elem).css('left', findPos(home).left).fadeIn(350);},
	                function(){$(elem).fadeOut(350)}
	
	);
	
	PDFlink();
	
	$('.belowfold').hide();
	$('.abovefold').append('<span class="showfold">more to this story &nbsp;&nbsp;</span>');
	
	$('.showfold').click(
	                        function()
	                        {
	                            
	                            $(this.parentNode.parentNode).find('.belowfold').show('slide', {direction:"down"}, 800);
	                            $(this).hide('slide', {direction:'left'}, 300);
	                        }
	                    )
	
	
	$(window).resize(function(){$(elem).css('left', findPos(home).left)});
	
	
	$('acronym').click(function(){
	                                var title = $(this).attr('title');
	                                var text = $(this).text();
	                                $(this).attr('title', text);
	                                $(this).text(title);
	                            });	
	
}

function test()
{
	
	pos.x = pos.x + 176;	
	//this.style.backgroundPosition = pos.getPosition();	
	
	var p = pos;
	
	var bn = function(k)
	{
	    $("#g").animate({
	        backgroundPosition:k.x
	        }, 600);
	}
	
	bn(p);
}


function accordion()
{
	jQuery('#navigation, #sismenu').Accordion({
	active: '.start',	
	alwaysOpen: false,
	head: 'first-child',
	navigation: true,
	animated:true,
	event:'click',
	showSpeed:200});
}


function PDFlink()
{
    $('a').each(function(){
                    var s = this.href.split('.');
                    var l = s.length;
                    
                    if(s[l-1].toLowerCase() == 'pdf' && !($(this).text().match("PDF")))
                    {
                        $(this).text($(this).text() + ' [pdf]');
                    }                    
                    
                                           
        
                        })

}



function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return {left:curleft, top:curtop};
}






jQuery().ready(function()
{
$('.accordion')
	.each(function(){	    
	    jQuery(this).Accordion({
				active: false,
				header: '.head',
				alwayOpen: false,
				navigation: true,							
				showSpeed:400})
	    
	
	
	})

})



$(document).ready(init)