﻿var flash_movie_folder_path = "/images/fla/";
var mp4_folder_path = "http://d2lqpc5wc9ttne.cloudfront.net/";
var ogv_folder_path = "http://d2lqpc5wc9ttne.cloudfront.net/";

function callvideo(divid, flv, img, width, height,is_autoplay) {
    var isiPad = navigator.userAgent.match(/iPad/i) != null;
    var isiPhone = navigator.userAgent.match(/iPhone/i) != null;
    var isiPod = navigator.userAgent.match(/iPod/i) != null;

    if (isiPad || isiPhone || isiPod) {
        callvideoHTML5(divid, flv, width, height);
    } else {
        if (is_autoplay) {
            callvideoFlashAutoStart(divid, flv, img, width, height);
        } else {
            callvideoFlashManualStart(divid, flv, img, width, height);
        }
    }
}

function callvideoFlashAutoStart(divid, flv, img, width, height) {
    var flashvars = {
        xml_path : './images/fla/cwplayer.xml',
        video_width : width,
        video_height: height,
        video_path: flash_movie_folder_path + flv,
        preview_image: '/wacoal2011/images/new_main/' + img
    };

    var params = { bgcolor: "#000000", wmode: "transparent", allowfullscreen: "true", loop: "true" };
    var attributes = {};
    swfobject.embedSWF("./images/fla/cwplayer.swf", divid, flashvars.video_width, flashvars.video_height, "9.0.0", "expressInstall.swf", flashvars, params, attributes);
}

function callvideoFlashManualStart(divid, flv, img, width, height) {
    var flashvars = {
        xml_path: "./images/fla/cwplayer-manualstart.xml", video_width: width, video_height: height,
        video_path: flash_movie_folder_path + flv, preview_image: img
    };
    var params = { bgcolor: "#000000", wmode: "transparent", allowfullscreen: "true", loop: "true" };
    var attributes = {};
    swfobject.embedSWF("./images/fla/cwplayer.swf", divid, flashvars.video_width, flashvars.video_height, "9.0.0", "expressInstall.swf", flashvars, params, attributes);
}

function callvideoHTML5(divid, flv, width, height) {
    var mp4_videosrc = mp4_folder_path + flv.replace('.flv', '.mp4');
    var ogv_videosrc = ogv_folder_path + flv.replace('.flv', '.ogv');
    
    var obj = document.getElementById(divid);
	if(obj) {
	    obj.innerHTML = '<video width="' + width + '" height="' + height + '" autoplay="autoplay" loop="true" poster="./images/new_main/preview.jpg" controls="true" preload="metadata"><source src="' + mp4_videosrc + '" type="video/mp4" /><source src="' + ogv_videosrc + '" type="video/ogg" /><source src="' + mp4_folder_path + flv.replace('.flv', '.ogv') + '" type="video/ogg" /><source src="' + mp4_folder_path + flv.replace('.flv', '.webm') + '" type="video/webm" />Your browser does not support the video tag.</video>';
	}
}



