function goPop(url) {
var winW = 850;
var winH = 700;
var winX = (screen.availWidth - winW) / 2;
var winY = (screen.availHeight - winH) / 2;
var features = 'left='+winX+',top='+winY+',width='+winW+',height='+winH+',toolbar=0,location=0,status=0,scrollbars= 1,resizable=0';
var popWin = window.open(url,popWin,features);
if (popWin) {
popWin.focus();
} else {
window.location.href = url;
}
}
function detailPop(url) {
var winW2 = 1000;
var winH2 = 700;
var winX2 = (screen.availWidth - winW2) / 2;
var winY2 = (screen.availHeight - winH2) / 2;
var features = 'left='+winX2+',top='+winY2+',width='+winW2+',height='+winH2+',toolbar=0,location=1,status=0,scrollbars= 1,resizable=0';
var popWin2 = window.open(url,popWin2,features);
if (popWin2) {
popWin2.focus();
} else {
window.location.href = url;
}
}

// Slideshow
function slideSwitch() {
    var $active = $('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');

    // uncomment the 3 lines below to pull the images in random order    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch()", 4000 );
});

// Lightstring
$(document).ready(function() {
	$(".LightString").mousedown( function() {
		$("#string").animate({ 
				marginTop: "-6px"
				}, 200 );
	}); 
	$(".LightString").mouseup( function() {
		$("#string").animate({ 
				marginTop: "-15px"
				}, 100 );
	}); 
});

// Dynamic Stylesheets
(function($)
	{
		var availableStylesheets = [];
		var activeStylesheetIndex = 0;
		
		$.stylesheetToggle = function()
		{
			activeStylesheetIndex ++;
			activeStylesheetIndex %= availableStylesheets.length;
			$.stylesheetSwitch(availableStylesheets[activeStylesheetIndex]);
		};
		
		$.stylesheetSwitch = function(styleName)
		{
			$('link[@rel*=style][title]').each(
				function(i) 
				{
					this.disabled = true;
					if (this.getAttribute('title') == styleName) {
						this.disabled = false;
						activeStylesheetIndex = i;
					}
				}
			);
			createCookie('style', styleName, 365);
		};
		$.stylesheetInit = function()
		{
			$('link[rel*=style][title]').each(
				function(i) 
				{
					availableStylesheets.push(this.getAttribute('title'));
				}
			);
			var c = readCookie('style');
			if (c) {
				$.stylesheetSwitch(c);
			}
		};
	}
)(jQuery);

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 var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
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;
}
function eraseCookie(name)
{
	createCookie(name,"",-1);
}
$(function()
	{
		$.stylesheetInit();
		$('#toggleSwitch').bind(
			'click',
			function(e)
			{
				$.stylesheetToggle();
				return false;
			}
		);
		$('.styleswitch').bind(
			'click',
			function(e)
			{
				$.stylesheetSwitch(this.getAttribute('rel'));
				return false;
			}
		);
	}
);
