function printandgoback() {
    window.print();
    history.go(-1);
}

function showRegion(id) {
	for(var q=19;q<35;q++){
		if (document.getElementById('cat_'+q)) {
			document.getElementById('cat_'+q).style.display = "none";
		}
	}
	document.getElementById('cat_front').style.display = "none";
	document.getElementById('cat_'+id).style.display = "inline";
}

function showRegionDefault() {
	for(var q=19;q<35;q++){
		if (document.getElementById('cat_'+q)) {
			document.getElementById('cat_'+q).style.display = "none";
		}
	}
	document.getElementById('cat_front').style.display = "inline";
}


var RFM = RFM || {};
jQuery(function () {
    RFM.spotlight.initialize();
});

RFM.spotlight = (function ($) {
    var that = {};

    /* public functions */
    that.initialize = function () {
        setupAudioPlayer();
        setupPopupPlayer();
        addUnloadAlertIfPlaying();
    };

    that.isPlaying = function() {
        var isPlaying = false
        $('.swf-player').each(function() {
            if (this.getConfig && (
                    this.getConfig().state == 'PLAYING' ||
                    this.getConfig().state == 'BUFFERING')) {
                isPlaying = true;
            }
        });
        return isPlaying;
    };

    /* private functions */

    function addUnloadAlertIfPlaying() {
        if ($('.swf-player').length > 0) {
            window.onbeforeunload = function () {
                if (RFM.spotlight.isPlaying()) {
                    return"Your player will be stopped if you leave this page.";
                }
            };
        }
    };

    function setupPopupPlayer() {
        $('a.popup-player').click(function() {
            var newwindow = window.open(this.href,'',
                'resizable=1,toolbar=0,location=0,status=0,menubar=0,scrollbars=1,width=515,height=390');
            newwindow.focus();
            return false;
        });
    };

    function setupAudioPlayer() {
        $('#audioplayer2').each(function(i) {
            var $this = $(this);
            var width = '280';
            $this.replaceWith("<div class='panel-player' id='panel-player-" + i + "'></div>");
            var so = new SWFObject('/media/player/jwplayer.swf', 'swf-player-'+i, width, '24', '9');
            so.addParam('allowfullscreen','true');
            so.addParam('allowscriptaccess','always');
            so.addParam('wmode','opaque');
            so.addParam('class','swf-player');
            if (location.href.indexOf('popup-player') !== -1) {
                so.addVariable('autostart', 'true');
            }
            so.addVariable('id', 'swf-player-'+i);
            //so.addVariable('duration','3123');
            so.addVariable('file',$this.attr('href'));
            so.addVariable('backcolor','F8981D');
            so.addVariable('frontcolor','FFFFFF');
            so.addVariable('plugins','gapro-1');
						so.addVariable('gapro.accountid','UA-308640-2');
						so.addVariable('gapro.trackstarts','true');
						so.addVariable('gapro.trackpercentage','true');
						so.addVariable('gapro.tracktime','true');
            so.write('panel-player-' + i);
        });
    };

    return that;
}(jQuery));