var prevImgIndex=-1;
var content_id =-1;
//set Featured Videos Section
function setFeaturedVideosSection(){
    var videoUrl="content/video/"+featured_videos[0][5];
   // oceanGetElementById("promoPic").innerHTML='<img onclick="oxylus_player('+featured_videos[0][0]+',event)" class="button" style="width:546px;height:302px;" id="promoImg" src="content/video/'+featured_videos[0][7]+'">';
    oceanGetElementById("playVideoTd").style.height="302px";
    oceanGetElementById("playVideoTd").innerHTML='<img alt="Oxylus player" onclick="oxylus_player('+featured_videos[0][0]+',event);" class="button" style="width:546px;height:302px;" id="promoImg" src="content/video/'+featured_videos[0][7]+'">';
    oceanGetElementById("playerBar").style.display = "block";

    //set video section
    var str="<table cellpadding=9 cellspacing=0 class='fullHeightWidth' style='background-image:url(images/featuredVideos_background.png?version=" + dcosmic_version_number + ");background-repeat:y-repeat;'>";
    var iconSrc="";
    for(var i=0;i<featured_videos.length;i=i+1){
        str = str +"<tr><td class='vTop' ><img class='button' src='content/Video/"+featured_videos[i][1]+"' style='width:96px;height:57px;' id='img"+featured_videos[i][0]+"' onclick='showVideo("+featured_videos[i][0]+",\""+featured_videos[i][2]+"\",\""+featured_videos[i][5]+"\",\""+featured_videos[i][7]+"\",event)'></td><td  class='vTop' style='padding-left:2px;pxadding-top:10px;'><table cellpadding=0 cellspacing=0 class='fullWidth'><tr><td><table cellspacing=0 cellpadding=0><tr><td class='vTop' ><img id='selimg"+featured_videos[i][0]+"' src='images/feature1_icon.png'></td><td id='titleTd"+featured_videos[i][0]+"' class='blueHeader' style='text-align:left;vertical-align:top;' >"+featured_videos[i][2]+"</td></tr></table></td></tr><tr><td class='rightSectionRegText' style='padding-left:5px;width:200px;'>"+featured_videos[i][3]+"</td></tr></table></td></tr>";
    }
    str = str + "</table>";

    oceanGetElementById("fvTd").innerHTML=str;    
    
}

//set Featured Content Section
function setFeaturedContentSection(){
    str="<table cellspacing=0 cellpadding=0>";
    
    var len= featured_contents.length;
    var tdCnt = len%3;
    var rowCnt = Math.floor(len/3);
    rowCnt = (rowCnt<=0)?1:rowCnt ;
 
    var rowTotal = (tdCnt!==0 && len>3)? rowCnt +1 : rowCnt ;
    var ctr=0;
    var rowStr ="";
    var tdStr ="";
    var x ="";
       
    for(var i=0;i<rowTotal ;i=i+1){
        rowStr = "<tr><td class='vTop' style='padding-top:10px'><table cellpadding=0 cellspacing=0 ><tr>";
        var tdTot=(i<rowCnt && len>=3)?3:tdCnt ;
        var src="";
        //form the td's
        for(var j=0;j<tdTot;j=j+1){
            if(featured_contents[ctr][1]!==""){
                var folder = "content/" + featured_contents[ctr][7];
                var type = featured_contents[ctr][7].toLowerCase().replace( / /gi, "" );
                if( type == 'blog' ) {
                    folder = "blog";
                } else if( type == 'link' ) {
                    folder = "links";
                } else if( type == 'press' ) {
                    folder = "press";
                } else if( type == 'event' ) {
                    folder = "events";
                } else if( type == 'news' || type == 'featuredguest' || type == 'creativeyou' || type == 'nextgen' ) {
                    folder = "news";
                } else if( type == 'competition' ) {
                    folder = "competition";
                } else if( type == 'testimonial' ) {
                    folder = "testimonial";
                }
                src="src='" + folder+"/"+featured_contents[ctr][1]+"'";
            }  

            
            tdStr =tdStr +"<td style='padding-right:5px;'><table cellpadding=0 cellspacing=0 ><tr><td ><img "+src+" style='width:211px;height:141px' align=top></td></tr><tr><td class='signInSubTitle' style='padding-top:5px;padding-bottom:5px;'>"+featured_contents[ctr][2]+ "</td></tr><tr><td  class='defaultText'><div style='overflow:hidden;height:26px;'>"+featured_contents[ctr][3]+"</div></td></tr><tr><td class='rowGap'></td></tr><tr><td><embed id=mybutton name=mybutton src='find_out_more.swf?version=" + dcosmic_version_number + "' wmode='transparent' style='width:101px;height:20px;' FlashVars='id="+ctr+"' type='application/x-shockwave-flash' ></embed></td></tr></table></td>";
 
            ctr = ctr + 1;            
        }
        x = x + rowStr + tdStr +"</tr></table></td></tr>";
        
        
        rowStr ="";tdStr ="";
    }
    str = str + x +"</table>";
    oceanGetElementById("fcTd").innerHTML=str;

}

// show the corresponding portfolio page
function showPortfolio(type,contentId){

    type = type.toLowerCase();
    type = type.replace( / /gi, "" );

    var url = "portfolio_"+type+".html.nocache?content_id="+contentId;
    if( type == 'blog' ) {
        url = "beyonder_blog.html.nocache";
    } else if( type == 'link' ) {
        url = "links.html.nocache";
    } else if( type == 'press' ) {
        url = "press.html.nocache";
    } else if( type == 'event' ) {
        url = "events.html.nocache";
    } else if( type == 'news' ) {
        url ="news_item1.html.nocache?newsId=" + contentId;
    } else if ( type == 'featuredguest' ) {
        url = "featured_guest_item.html.nocache?newsId=" + contentId;
    } else if ( type == 'creativeyou' ) {
        url = "creative_you_item.html.nocache?newsId=" + contentId;
    } else if ( type == 'nextgen' ) {
        url = "next_gen_item.html.nocache?newsId=" + contentId;
    } else if( type == 'competition' ) {
        url = "competitions_item1.html.nocache?compId=" + contentId;
    } else if( type == 'testimonial' ) {
        url = "testimonial.html.nocache";
    }

    location.href=url;

}

//show video
function showVideo(id,title,videoUrl,bannerPic,evt){

    oceanGetElementById( "playVideoTd").innerHTML="";
    oceanGetElementById("playVideoTd").style.height="302px";
   // oceanGetElementById("playVideoTd").style.display="none";
  //  oceanGetElementById("promoPic").style.display="block";    
    oceanGetElementById("playerBar").style.display="block";

//    oceanGetElementById("promoPic").innerHTML='<img onclick="oxylus_player('+id+',event)" class="button" style="width:546px;height:302px" id="promoImg" src="content/video/'+bannerPic+'">';

    oceanGetElementById("playVideoTd").innerHTML='<img onclick="oxylus_player('+id+',event)" class="button" style="width:546px;height:302px" id="promoImg" src="content/video/'+bannerPic+'">';
         
    content_id=id;
    // display the find out more button
    oceanGetElementById( "findOutMoreBtnTd" ).innerHTML = "<embed id=mybutton name=mybutton src=\"find_out_more.swf?version=' + dcosmic_version_number + '\" wmode=\"transparent\" style=\"width:101px;height:20px;\" FlashVars=\"id=-1\" type=\"application/x-shockwave-flash\"></embed>";

    if(prevImgIndex!=-1){
        oceanGetElementById("img"+prevImgIndex).style.border="0px solid yellow";
        oceanGetElementById("selimg"+prevImgIndex).src="images/feature1_icon.png";
        oceanGetElementById("titleTd"+prevImgIndex).style.color="rgb(32,174,230)";
    }

    var imageIndex="img"+id;
    oceanGetElementById(imageIndex).style.border="1px solid yellow";
    
    prevImgIndex=id;
    
    oceanGetElementById("selimg"+id).src="images/feature2_icon.png";
    oceanGetElementById("titleTd"+id).style.color="#fff000";
    oceanGetElementById("videoTitleTd").innerHTML=title;

    //changeVideo_old( "playVideoTd",  videoUrl);
    //changeVideo(videoUrl);
    //oceanGetElementById("promoImg").onclick=adobe_playvideo(videoUrl);

}

//show portfolio video page for the selected video
function showPortfolioVideo(){

    if(content_id!=-1){
        location.href="portfolio_video.html.nocache?content_id="+content_id;
    }
}


// change the video currently being played by the flash movie player
// the first param is the id of the td / div containing the player
// the second is the url to the new video
function changeVideo_old( id, newUrl ) {

    // store the actual markup as a var
    var html = '<object id=myid classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http' + '://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0"  he'+'ight="275" wi'+'dth="560" >';
    html = html+'<param name="salign" id="salign" value="lt">';
    html = html+'<param name="quality" id="quality" value="high">';
    html = html+'<param name="scale"  id="scale" value="exactfit">';
    html = html+'<param name="play" id="play" value="true">';
    html = html+'<param name="wmode" id="wmode" value="transparent">';
    html = html+'<param name="allowscriptaccess" id="allowscriptaccess" value="always">';
    html = html+'<param id="movie" name="movie" value="">';
    html = html+'<param name="FlashVars" id="FlashVars" value="&streamName=&autoPlay=true&autoRewind=true">';
    html = html+'<embed flashvars="&streamName=&autoPlay=true&autoRewind=true" quality="high" scale="exactfit" salign="LT" type="application/x-shockwave-flash" pluginspage="http' + '://www.macromedia.com/go/getflashplayer" src="" wmode="transparent" he'+'ight="275" wi'+'dth="560">';
    html = html+'</embed>';
    html = html+'</object>';

    // look for our first placeholder    
    var firstFind = html.indexOf( "&streamName=" );
    var secondFind = html.indexOf( "&", firstFind + 1 );
    
    // change first video source
    html = html.substring( 0, firstFind ) + "&streamName=" + newUrl + html.substring( secondFind );

    // look for our second placeholder    
    firstFind = html.indexOf( "&streamName=", secondFind );
    secondFind = html.indexOf( "&", firstFind + 1 );


    // change second video source
    html = html.substring( 0, firstFind ) + "&streamName=" + newUrl + html.substring( secondFind );

     // look for our third placeholder    
    firstFind = html.indexOf( "name=\"movie\" value=\"\"" );
    secondFind = html.indexOf( ">", firstFind );


    // change third video source
    html = html.substring( 0, firstFind ) + "name=\"movie\" value=\"" + newUrl + html.substring( secondFind - 1 );

    // look for our fourth placeholder    
    firstFind = html.indexOf( "src=\"\"" );
    secondFind = html.indexOf( "\"", firstFind + 5 );


    // change fourth video source
    html = html.substring( 0, firstFind ) + "src=\"" + newUrl + html.substring( secondFind );

    // draw out fresh player
    oceanGetElementById( id ).innerHTML = html;

}

//change video
function changeVideo(url){

    //var vurl = "flvplayer.swf?theFile="+url;
    var vurl = url;
    //var so = new SWFObject("flvplayer.swf?theFile=20051210-w50s.flv&defaultImage=graphic.jpg&theVolume=100&startPlayingOnload=yes&popUpHelp=no&bufferSeconds=2&videoSmoothing=yes","flvplayer","400","400","8","#000000");

    var so = new SWFObject(vurl+"&defaultImage=graphic.jpg&theVolume=100&startPlayingOnload=yes&popUpHelp=no&bufferSeconds=2 &videoSmoothing=yes","flvplayer","560","305","8","#000000");

    so.addParam("movie",vurl+"&defaultImage=graphic.jpg&theVolume=100&startPlayingOnload=yes&popUpHelp=no&bufferSeconds=2&videoSmoothing=yes");
    so.addParam("bgcolor","#000000");
    so.addParam("wmode","transparent");
    so.write("playVideoTd");
}

// button calls this method
function findOutMore_onClick( idVal ) {

    if(idVal==-1){
        showPortfolioVideo();
    }else if(idVal==-2){
        var url=home_intro[0][3];
        location = url;
        /*
        if(url.indexOf("http") == -1){
            url="http" + "://"+url;
        }
        open(url,"","status=1");
        */
    }else{
        var type=featured_contents[idVal][7];
        var contentId=featured_contents[idVal][0];
        showPortfolio(type,contentId);
    }    

}

//set introduction section
function setIntroduction(){
    oceanGetElementById("IntroTitle").innerHTML=home_intro[0][1];
    home_intro[0][2]=home_intro[0][2].replace(/\n/g,"<br>");
    oceanGetElementById("IntroDesc").innerHTML=home_intro[0][2];
}

//street adobe_playvideo
function adobe_playvideo(videoUrl){
    oceanGetElementById("promoPic").style.display="none";
    oceanGetElementById("playVideoTd").style.display="block";
    var html = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http' + '://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" he'+'ight="275" wi'+'dth="560" name="FLVPlayer" id="FLVPlayer">';
    html = html+'<param id="movie" name="movie" value="'+videoUrl+'" />';
    html = html+'<param id="wmode" name="wmode" value="opaque">';
    html = html+'<param id="quality" name="quality" value="high" />';
    html = html+'<param id="salign" name="salign" value="" />';
    html = html+'<param id="bgcolor" name="bgcolor" value="#000000" />';
    html = html+'<param id="allowFullScreen" name="allowFullScreen" value="false" />';
    html = html+'<param id="scale" name="scale" value="exactfit" />';
    html = html+'<param id="allowScriptAccess" name ="allowScriptAccess" value="always" />';
    html = html+'<param id="play" name="play" value="true" />';
    html = html+'<param id="loop" name="loop" value="true" />';
    html = html+'<param id="menu" name="menu" value="true" />';
    html = html+'<embed src="'+videoUrl+'" he'+'ight="275" wi'+'dth="560" quality="high" allowScriptAccess="always" allowFullScreen="false" wmode="transparent" sxcale="exactfit" play="true" loop="true" menu="true" bxg'+'color="#ffffff" id="FlashVars" name="FLVPlayer" salign="" type="application/x-shockwave-flash" pluginspage="http' + '://www.macromedia.com/go/getflashplayer">';
    html = html+'</object>';

   //alert( html );

    // draw out fresh player
    oceanGetElementById( "playVideoTd").innerHTML = html;
}

//oxylus player
function oxylus_player(id,evt){
    var file = "settings_content_"+id+".xml";
  //  oceanGetElementById("promoPic").style.display="none";
    oceanGetElementById("playerBar").style.display="none";
   // oceanGetElementById("playVideoTd").style.display="block";
    oceanGetElementById("playVideoTd").style.height="333px";
    var so = new SWFObject("VPlayer.swf", "flash", "546", "315", "8", "#303030");                            
    so.addVariable("xml", file);
    so.addParam("wmode","transparent");
    so.write("playVideoTd");
}

//func onclick of see more videos button
function moreVideos_onClick(){
//    location.href='portfolio_landing.html.nocache?type=2';
    location.href='featured_guest.html.nocache?type=Video';
}

// button share onclick
function share_onClick() {
    // do nothing
}
