var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;

$(document).ready(function() {

// external links       
extLinks();
jsddm_setup();

$( '#jsddm li li a' ).each(function () {
var shortText = $(this).text().trim().substring(0, 25) + "...";
$(this).text(shortText);
});



$('#scroll').cycle({ fx:'fade', timeout: 6000, delay:  -2000 } );


var $nav = $('#articleNav');
  
  if ( $nav.length ) {
    var $nextArticle = $('<span id="nextArticle"><span /><span class="edge" /></span>').css('opacity', 0);
    
    $nav.after( $nextArticle );
    
    $nextArticle.hover(function (event) {
      event.stopPropagation();
    });
    
    $nav.find('li').hover(function () {
      $nextArticle.find('span:first').html( $(this).html() ).end().stop().fadeTo(100, 1);
    }, function (event) {
      $nextArticle.stop().fadeTo(500, 0);
    });
  }


$("a[rel='colorbox']").colorbox();
$('li.sectionheader').find("a:first").click(function() {
		return false;
	});
	
$('#forum').find("a:first").click(function() {
        window.open( 'http://forum.soundartradio.org.uk/' );
		return false;
	});
	
$('#forum').find("a:first").hover(function() {
   
        $( this ).attr( 'title', 'Open the Soundart Radio Forum in a new window' );

        });


var firstAudioclip=$(".divshare-item:first a").attr("id");
var firstAudioclipTitle=$(".divshare-item:first a").attr("title");



$('#audioclip').append("<h3>"+firstAudioclipTitle+"</h3><object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" width=\"335\" height=\"28\" id=\"divaudio2\"><param name=\"movie\" value=\"http://www.divshare.com/flash/audio?myId="+firstAudioclip+"\" />    <embed src=\"http://www.divshare.com/flash/audio?myId="+firstAudioclip+"\" width=\"335\" height=\"28\" name=\"divaudio2\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\"></embed></object>");

$(".divshare-item a").click(function(){
var audioclipID=$(this).attr("id");
var audioclipTitle=$(this).attr("title");

$("#audioclip").empty();
$("#audioclip").append("<h3>"+audioclipTitle+"</h3><object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" width=\"335\" height=\"28\" id=\"divaudio2\"><param name=\"movie\" value=\"http://www.divshare.com/flash/audio?myId="+audioclipID+"\" />    <embed src=\"http://www.divshare.com/flash/audio?myId="+audioclipID+"\" width=\"335\" height=\"28\" name=\"divaudio2\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\"></embed></object>");
return false;
});	

$('.divshare-item a').each(function(index) {
    $(this).html(index+1);
  });





if($.cookie('TEXT_SIZE')) {
		$('body').addClass($.cookie('TEXT_SIZE'));
	}
	$('.resizer a').click(function() {
		var textSize = $(this).parent().attr('class');
		$('body').removeClass('small medium large').addClass(textSize);
		$.cookie('TEXT_SIZE',textSize, { path: '/', expires: 10000 });
		return false;
	});
	

// submit button - change bgd on hover, update message in title tag
$( '#search-box input.search-button , div.soundart_form input.fbsubmit' ).hover( function() {
    
        $( this ).addClass( 'hover' );
        $( this ).css( 'cursor', 'pointer' );
        $( '#search-box input.search-button' ).attr( 'title', 'Click to see search results' );
        $( 'div.soundart_form input.fbsubmit' ).attr( 'title', 'Click to submit form' );

    }, function() {
        
            $( this ).removeClass( 'hover' );
    });
    
    
    
     

$("a.launchplayer").click(function(e){
var url = '/player/console/';
var windowName = "radioPlayer";;
var windowAttr = 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=380,height=660';
window.open(url, windowName, windowAttr);
e.preventDefault();
});
	 

	

    
 // end onload
});



// external links
function extLinks() {

    $("a[rel='external']").click( function(){
        window.open( this.href );
        return false;
    });
    
};


function jsddm_open() {
jsddm_canceltimer();
	jsddm_close();
	ddmenuitem = $(this).find('ul').eq(0).show();
	}

function jsddm_close() {
if(ddmenuitem) ddmenuitem.hide();
}

function jsddm_timer(){	
closetimer = window.setTimeout(jsddm_close, timeout);
}

function jsddm_canceltimer() {	
if(closetimer)
	{	window.clearTimeout(closetimer);
		closetimer = null;}
		}

function jsddm_remove() {
$('#jsddm > li').unbind('mouseover', jsddm_open);
$('#jsddm > li').unbind('mouseout',  jsddm_timer);
}

function jsddm_setup() {
$('#jsddm > li').bind('mouseover', jsddm_open);
$('#jsddm > li').bind('mouseout',  jsddm_timer);
}

document.onclick = jsddm_close;

    
