$(document).ready(function(){
 	$("ul.sf-menu").supersubs({ 
			minWidth:    12,   // minimum width of sub-menus in em units 
			maxWidth:    27,   // maximum width of sub-menus in em units 
			extraWidth:  1     // extra width can ensure lines don't sometimes turn over due to slight rounding differences and font-family 
        })
        .superfish({ 
		delay:500, 
		animation:{opacity:"show",height:"show"}, 
		speed:"fast", 
		autoArrows:true, 
		dropShadows:true
	}); 
	
	$("#gallery").jqGalViewII();

	$(".fm-opt").show();
	$("a.fm-opt-toggle").click(function(){
		$(".fm-opt").slideToggle("slow");
	});

	$("#fm-form").validate();
	
	$("a[title='Delete']").click(function(){
		return confirm("Are you sure you want to delete?");									
	});	
	
	$("p.message").each(function(i,o){
		$.jGrowl(o.innerHTML);
	}).hide();	
	
	$(".datatable").dataTable({"bSort":false});
	
	$(".flyout").flyout();
	
	$("#fm-form label").tooltip();

    $('.rounded').corners();
    $('.rounded').corners(); /* test for double rounding */
    $('table', $('#featureTabsContainer .tab')[0]).each(function(){$('.native').hide();});
    $('#featureTabsContainer').show();
    //tab(0);

	// mouseover image swap
	$("#buttons img").hover(function() {
		$(this).attr("src", $(this).attr("src").split(".").join("-over."));
	  }, function() {
	    $(this).attr("src", $(this).attr("src").split("-over.").join("."));
	});
	
	// banner slideshow...
	$bannerplaceholder = $('#welovetech');
	if ( $bannerplaceholder.size() )
	{
		$bannerplaceholder.css('height', $bannerplaceholder.find('img').eq( 0 ).attr('height') ).slideshow( {timeout: '7000'} );
	}
	
	// expanding CMS style
	$('.toggle')
		.hide()
		.before( '<div class="slidetoggle">Click to show more information</div>' )
		.prev()
		.css( 'cursor','pointer' )
		.click( function(){
			$panel = $( this ).next();
			if ( ( $panel ).is( ':hidden' ) ) {
				$( this ).text( $( this ).text().replace( /show/, 'hide' ) );
			}
			else {
				$( this ).text( $( this ).text().replace( /hide/, 'show' ) );
			}
			$panel.slideToggle( 500 );
		});
		
	// append &raquo; to all text links (excludes mailto)
	//$( "#content a[href!='mailto:']:not( :contains( '&raquo;' ) )" ).append( ' &raquo;' );
	//$( "#content a:not(:contains('mailto:'))" ):not( :contains( '&raquo;' ) ).append( ' &raquo;' );
	

	// assign listeners tracking downloads etc
	if (typeof(pageTracker) == "object") 
	{
		$('a[href]').click(function(){
			var linksto = this.href;

			if (linksto.indexOf('mailto:')==0)
			{
				pageTracker._trackEvent('mailto', 'click', linksto.substring(7));	
			}
			else if (linksto.match(/\.(pdf|doc|zip|ppt|exe|xls|docx)+$/))
			{
				pageTracker._trackEvent('download', listLast(linksto,'.'), linksto);
			}
			else if (linksto.match(/\.(avi|mov|wmv|flv|f4v|mp4)+$/))
			{
				pageTracker._trackEvent('video', listLast(linksto,'.'), linksto);
			}
			else if (linksto.match(/\.(mp3|wav|aac|wmf)+$/))
			{
				pageTracker._trackEvent('audio', listLast(linksto,'.'), linksto);
			}
			else if (!linksto.match(document.domain))
			{
				pageTracker._trackEvent('exit', 'click', linksto);
			}
		});
	}

	
});		 