var playVideo = function( v, ajax ){
    var xv = v;
    var xajax = ajax;
    $("#splashimage").show();
    
    window.setTimeout(function(){
        playVideo2( xv, xajax );
    },window.SplashImageShowTime);
}

var playVideo2 = function(v, ajax) {
    $("#splashimage").hide();
    
    var videoclass = v.attr("class");
    var type = v.attr("type");
    var id = v.attr("id");
    var href = encodeURI( $.trim( v.html() ) );
    $("#detial_b2").parent().show();

    if(videoclass != "banners") { 
        if(ajax) {
            getvideotoolsinfo(id);
        }
       
        if(!$("#hidevideoinfo").attr("iselearn")) {
            $("#recommendationbtn23").parent().show();
        }
    
        if($("#hidevideoinfo").attr("email")) {
            $("#emailinfo a").attr("href", "mailto:"+$("#hidevideoinfo").attr("email"));
            $("#emailinfo").show();
        }
        if($("#hidevideoinfo").attr("url1")) {
            $("#url1info a").attr("href", $("#hidevideoinfo").attr("url1"));
            $("#url1info").show();
        }
        if($("#hidevideoinfo").attr("url2")) {
            $("#url2info a").attr("href", $("#hidevideoinfo").attr("url2"));
            $("#url2info").show();
        }

        $("#videolist .playing").attr("class","wait");
        v.attr("class","playing");

        if($("#videolist span:first-child").next().attr("class") == "playing") {
            $("#prev").hide();
        } else{
            $("#prev").show();
        }
        if($("#videolist span:last-child").prev().attr("class") == "playing") {
            $("#next").hide();
        } else {
            $("#next").show();
        }
    } else {
        if($("#videolist span").length  <= 3) {
            $("#next").hide();
        };
        if(id == "front") {
            $("#prev").hide();
        }
    }
    if(type == "swf"){
        
        $("#flv").hide();
        $("#swf").show();
        var div_content = "<object" +
        " classid = \"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"" +
        " id = \"swfvideoid\"" +
        " codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\"" +
        " width=\"640\"" +
        " height=\"360\">" +
        " <param name=\"movie\" value=\"" + href + "\" />" +
        " <param name=\"quality\" value=\"high\" />" +
        " <param name=\"wmode\" value=\"opaque\" />" +
        " <param name=\"allowFullScreen\" value=\"true\" />" +
        " <embed " +
        " src=\"" + href + "\"" +
        " quality=\"high\"" +
        " wmode=\"opaque\"" +
        " allowfullscreen=\"true\"" +
        " pluginspage=\"http://www.macromedia.com/go/getflashplayer\"" +
        " type=\"application/x-shockwave-flash\"" +
        " width=\"640\"" +
        " height=\"360\">" +
        " </embed>" +
        " </object>";
        $("#swf").html(div_content);
         
    }

    if(type == "flv" || type == "mp4") {
        var flashurl = $("#flv").attr("url");
        var uselogo = $("#hidevideoinfo").attr("logo");
        var fvideo = $("#hidevideoinfo").attr("fvideo");
        var urlinfo = "";
        var pwk = $("#hidevideoinfo").attr("pwk");
        var fwk = $("#hidevideoinfo").attr("fwk");
        if( uselogo ) {
            if( fvideo ) {
                urlinfo = fwk;
            }else {
                urlinfo =  pwk;
            }
        }else {
            urlinfo = '../images/blank.png';
        }
        var start = $("#hidevideoinfo").attr("start");

        $("#swf").hide();
        $("#flv").show();
        var divcontent = "<a href=\"" + href + "\"" + " style=\"display:block;width:640px;height:384px;\" id=\"player\"></a>";
        $("#flv").html(divcontent);
 
        createPlayer({
            ppsUrl: flashurl+"flash/pps.swf",
            swf: flashurl+"flash/playerProductInstall.swf",
            id: "flv",
            src: href,
            logo: urlinfo,
            onFinished: function(){
                if(id == "front") {
                    playVideo($("#videolist .playing"), false);
                } else if(id == "back"){
                } else {
                    playNext();
                }
            },
            width: 640,
            height: 398,
            start: start
        });
    }
    
    if(ajax && videoclass != "banners") {
        vidoeinfoajaxcallback(id);
    }
  
}

var playNext = function() {
    ajax = true;
    var video = $("#videolist .playing").next();
    if(video.length > 0) {
        playVideo(video, ajax);
    }

}

var playPrev = function(){
    ajax = true;
    var video = $("#videolist .playing").prev();
    if(video.length > 0) {
        playVideo(video, ajax);
    }
}




