jQuery.jQueryRandom = 0;
jQuery.extend(jQuery.expr[":"],{
    random: function(a, i, m, r) {
        if (i == 0) {
            jQuery.jQueryRandom = Math.floor(Math.random() * r.length);
        };
        return i == jQuery.jQueryRandom;
    }
});

$(document).ready(function(){ 
	
	// top nav
	$("ul.topnav").superfish({autoArrows: false, animation: {height:'show'}, dropShadows: false, speed: 200, delay: 200 })
		.find('li:first').addClass('first');
	$("ul.topnav ul").each(function(){ $(this).find('a:first').addClass('first'); $(this).find('a:last').addClass('last');});
	
	// homepage
	if ($('#home .scroll').length) {
		//$('.scroll img').imgpreload(function(){
			$('.scroll').jScrollPane({ scrollbarWidth:15, scrollbarMargin:17, showArrows:true, dragMaxHeight:17, dragMinHeight:17 });
		//});
	} else {
		$('.scroll').jScrollPane({ scrollbarWidth:15, scrollbarMargin:17, showArrows:true, dragMaxHeight:17, dragMinHeight:17 });
	}
	
	// customers
	$('div.custlogos img').click(function() {custAbstract(this); return false;});
	if ($('div.custcasestudy img').length == 0) { var custRandom = $('div.custlogos').children('img:random'); custAbstract(custRandom); }
	
	function custAbstract(obj) {
		$('div.custcasestudy').empty(); 
		$(obj).next('div.cs').clone().appendTo('div.custcasestudy').hide().fadeIn("fast", function() { 
			if(jQuery.browser.msie) $(this).get(0).style.removeAttribute('filter'); 
		});
	}
	/*var prodHover = {
		interval:100,
		timeout: 200,
		over: openProd,
		out: function(){ $('span.prodarrow').hide(); $('div.prod').slideUp(200); }
	};
	
	$("ul.topnav li.prodlink").hoverIntent( prodHover );
	
	function openProd() { 
		var boxPos = $('div.wrapper').offset().left - $('li.prodlink').offset().left;
		var arrowPos = $('li.prodlink a').width() / 2 - 5;
		$('span.prodarrow').css('left',arrowPos).show(); 
		$('div.prod').css('left', boxPos).slideDown(200);
	}
	*/
}); 


var newwindow = '';

/* popup a window, but dont clear the page if it already exists by reloading */

function launchPopup(popupwinurl,options) {

		if (!options) {
			options = 'scrollbars=yes,location=yes,menu=yes,titlebar=yes,toolbar=yes';
		}

        if (!newwindow.closed && newwindow.location) {
                   newwindow.location.href = popupwinurl; // bring up window from behind, refresh the location
        }
        else {
                /* no window, open new */
                newwindow=window.open(popupwinurl ,'pop',options);
                if (!newwindow.opener) newwindow.opener = self;
        }
        if (window.focus) {newwindow.focus()}
        return false;
}


$(document).ready(function() {

  $('.seemore').click(function() {
  
  $(this).next('.expandable').animate({
    height: 'toggle'
  },  function() {
    // Animation complete.
  });
  return false; 
});

});
    
/* drop in some random highslide code for each page so we can embed some nice thumb images, by putting class=expandPicture on the <a> tag. */
$(document).ready(function() {
hs.graphicsDir = '/scripts/highslide/graphics/';

	$("a.expandPicture").each( 

	function (i){	// apply the class so client won't have to apply 2 classes.
		$(this).addClass("highslide");	
	});
	
	$("a.expandPicture").click( function() {
	 return hs.expand($(this).get(0), { captionEval: 'this.thumb.alt' });
	});
	
});



