function setMovieId( sender, id ) {
	var flashMovie = document.getElementById('syndicatedSWF');
	litags = document.getElementsByTagName("LI");
	clipListindex = 0;
	clipListLen = litags.length;
	for (clipListindex =  0; clipListindex < clipListLen; clipListindex++)
	{
	    li = litags[clipListindex];
	    if (li.className == "clipRow_active") li.className = "clipRow";
	}
	
	if(sender.parentNode && sender.parentNode.className == "clipRow") sender.parentNode.className = "clipRow_active";

	if (flashMovie) flashMovie.setMovie( id );
	refreshAdCalls();
	
	return false;
}

// sets the state of list itemn to selected
function setItemSelected( id ) 
{
    var litags = document.getElementsByTagName("LI");
    var clipListindex = 0;
    var clipListLen = litags.length;
	
    for (clipListindex =  0; clipListindex < clipListLen; clipListindex++)
    {
        var li = litags[clipListindex];
	    
	    if (li.className == "clipRow" || li.className == "clipRow_active")
	    {
            if (li.getAttribute("id") != id)
            {
                if (li.className == "clipRow_active") li.className = "clipRow";
            }
            else 
            {
                li.className = "clipRow_active";
            }
        }
    }
	return false;
}

// update ads in iframes
function refreshAdCalls() {
    ord = Math.random() * 10000000000000000;
    setCookie("__TEMP_ADORD", ord);
    $('iframe').each(function(i) {
        if (this.src != '' && this.src.indexOf('adsource.aspx') >= 0) {
            var index = this.src.indexOf('&adord=');
            if (index >= 0) {
                var iframeSrc = this.src.substring(this.src.indexOf('&adord='));
                iframeSrc = iframeSrc.substring(0, iframeSrc.indexOf(';'));
                this.src = this.src.replace(iframeSrc, '&adord=' + (Math.random() * 10000000000000000) + ';');
            }
            else {
                this.src = this.src + '&adord=' + (Math.random() * 10000000000000000) + ';';
            }
        }
    });
}

$(document).ready( function() {    
    $('#cliplist a').click( function( event ) {
        event.preventDefault();
        var urlparts = $(this).attr('href').split( '/' );
        var movieid = urlparts[ urlparts.length - 2 ];
        setMovieId( this, movieid );
     } );
     
} );

function showCompanionAd( url ) {
    if (typeof ord=='undefined') { ord = getCookie("__TEMP_ADORD"); }
	var iFrame = document.getElementById( 'companion' );
	var iFrameContainer = document.getElementById( 'companionArea' );
	if ( !iFrame ) { return; }
    if (iFrame.src == '' || iFrame.src.indexOf('shim.gif') >= 0) { iFrame.src = url + ";ord=" + ord; }
    else { iFrame.src = iFrame.src; }
    if ( !iFrameContainer ) { return; }
    $( iFrameContainer ).fadeIn( 'normal' );
}
function hideCompanionAd() {
	var iFrame = document.getElementById( 'companion' );
	var iFrameContainer = document.getElementById( 'companionArea' );
	if ( !iFrame) { return; }
    if ( iFrameContainer ) { $( iFrameContainer ).fadeOut( 'normal' ); }
    iFrame.src = "http://cache.reelzchannel.com/assets/content/general/shim.gif";
}