var activeMiniTrailer = false;

function videoFinish() {
    if (activeMiniTrailer) {
    	activeMiniTrailer.addClass('postroll');
    	activeMiniTrailer.find('.video_overlay').show();
    	activeMiniTrailer.children('embed').remove();
    	activeMiniTrailer.children('object').remove();
    	activeMiniTrailer = false;
	}
}
function miniTrailer(spot, id, forcejoin) {
	videoFinish();

	var player = (typeof spot == 'string' ? $(spot) : spot);
	player.children().css('display', 'none');

	activeMiniTrailer = player;

	var videooptions_url = "http://www.realslutparty.com/default/get_scene/" + id + "/autoplay-1/show-info-0" + (forcejoin ? "/force-1" : "");

	player.flash(
		{
			src: "http://static.contentabc.com/player/wide_tour_player.swf",
			width: 470,//478,
			height: 282,
			wmode: "transparent",
			align: "middle",
			allowfullscreen:true,
			allowscriptaccess: "always",
			allownetworkaccess: "always",
			flashvars: {
				options: videooptions_url
			}
		},
		{version:"10.0.22"}
	);
}

function introVideo() {
    var previewer = $('div#tour_trailer');
    previewer.html('');
    previewer.parents('a').click(function() { return false; });

	var header_version = $('img#common_header').attr('rel');
	var videooptions_url = "http://static.contentabc.com/intros/rsp/rsp-tr3_trailer.xml";

	if(header_version == 1)
	{
		videooptions_url = "http://static.contentabc.com/intros/rsp/rsp-tr3_trailer.xml";
	}
	else if(header_version == 2)
	{
		videooptions_url = "http://static.contentabc.com/intros/rsp/rsp-tr3_trailer3.xml";
	}
	else if(header_version == 3)
	{
		videooptions_url = "http://static.contentabc.com/intros/rsp/rsp-tr3_trailer2.xml";
	}

    previewer.flash(
        {
            src: "http://static.contentabc.com/player/wide_tour_player.swf",
            width: 397,
            height: 223,
            wmode: "transparent",
            align: "middle",
            allowfullscreen:true,
            allowscriptaccess: "always",
            allownetworkaccess: "always",
            flashvars: {
                options: videooptions_url
            }
        },
        {version:"10.0.22"}
    );
}

$(document).ready(function(){

	introVideo();

    $('a.playbtn').click(function() {
        if($(this).attr('href') == '#')
        {
        	var id = $(this).attr('id').replace('btn_', '');
			miniTrailer($(this).parent().parent(), id, 0);
			return false;
        }
    });


    $('.play_overlay').click(function() {
        	name 	= $(this).attr('yahootrackid');
        var url 	= $(this).attr('rel');
        if (name && YWATracker){
			name = 'RSP DEFAULT PG HOME ' + name;
			YWATracker.setCF(2, name);
			YWATracker.setAction("03");
			YWATracker.submit_action();
		}
		window.location= url;

    });
});
