var Utils = {};
Utils.Path = '';
Utils.mobileDeviceFlag = false;
var flag=true;
var cardNumber=0;
var downloadpdf;
var CardNameArray=["Home"];
$(document).ready(function () {
    $(".se-pre-con").fadeOut("slow");
    if ((navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) && !(window.location.href.includes('http')))
        Utils.mobileDeviceFlag = true;
    setTimeout(function () {
        $('#Homepage').css('background-image',"url(" + Utils.Path +"images/mainpagebig.png"); 
        init(AppData[cardNumber].data,AppData[cardNumber].data.length,"Energypage(this)");
    }, 100);
});
init = function (Data,DataLength,functionName)
{
    console.log(cardNumber)
    document.getElementById("LastPage").style.display = "none";
    console.log(Data,DataLength,functionName);
    for (j = 0; j <DataLength; j++) 
    {
        outerDiv = document.createElement("DIV");
        outerDiv.setAttribute("id", "outerDiv"+j);
        outerDiv.setAttribute("class", "col-lg-4 col-md-6 mb-5 d-flex justify-content-center align-items-center");
        document.getElementById("mainBody").appendChild(outerDiv);

        outerDiv1 = document.createElement("DIV");
        outerDiv1.setAttribute("id", "outerDiv1"+j);
        outerDiv1.setAttribute("class", "item p-3");
        outerDiv.appendChild(outerDiv1);
        for (i = 0; i <1; i++) 
        {
        imgDivCard= document.createElement("div");
        imgDivCard.setAttribute("id", "outerimgDivCard"+j);
        imgDivCard.setAttribute("class", "card card-hover-effect ");
        imgDivCard.setAttribute("onclick", ""+functionName);
        imgDivCard.setAttribute("Img", Data[j].Img);
        imgDivCard.setAttribute("Title", Data[j].Text);
        imgDivCard.setAttribute("Info",Data[j].information);
        imgDivCard.setAttribute("Src",Data[j].videoSrc);
        outerDiv1.appendChild(imgDivCard);
        
        imgDiv = document.createElement("img");
        imgDiv.setAttribute("id", "imgDiv"+j);
        imgDiv.setAttribute("class", "card-img-top card-img-fixed p-3");
        imgDiv.src = Utils.Path +"images/"+Data[j].Img;
        imgDivCard.appendChild(imgDiv);

        textDiv = document.createElement("DIV");
        textDiv.setAttribute("id", "outertextDiv"+j);
        textDiv.setAttribute("class", "row fontCls TitleText px-3 py-3");
        imgDivCard.appendChild(textDiv);
        document.getElementById("outertextDiv"+j).innerHTML= Data[j].Text;

        ExploreDiv = document.createElement("DIV");
        ExploreDiv.setAttribute("id", "outerExploreDiv"+j);
        ExploreDiv.setAttribute("class", "col-12 card-footer bg-transparent border-top d-flex align-items-center justify-content-between");
        imgDivCard.appendChild(ExploreDiv);

        cardFooterDiv = document.createElement("DIV");
        cardFooterDiv.setAttribute("id", "cardFooterDiv"+j);
        cardFooterDiv.setAttribute("class", "cardFooterText col-6  col-sm-8 col-md-5 col-lg-6 col-xl-8");
        ExploreDiv.appendChild(cardFooterDiv);
        document.getElementById("cardFooterDiv"+j).innerHTML= Data[j].cardFooterText;

        arrowDiv = document.createElement("DIV");
        arrowDiv.setAttribute("id", "arrowDiv"+j);
        arrowDiv.setAttribute("class", "row");
        ExploreDiv.appendChild(arrowDiv);
        arrowimgDiv = document.createElement("img");
        arrowimgDiv.setAttribute("id", "arrowimgDiv"+j);
        arrowimgDiv.setAttribute("class", "arrowimg col-2  col-sm-8 col-md-5 col-lg-12 col-xl-12");
        arrowimgDiv.src = Utils.Path +"images/arrow.png";
        arrowDiv.appendChild(arrowimgDiv);
        }
    }
    if(flag==true)
    {
        mainouterDiv = document.createElement("DIV");
        mainouterDiv.setAttribute("id", "NewArrivalmainouterDiv");
        mainouterDiv.setAttribute("class", " row mb-5  bg-light d-flex align-items-stretch ");
        document.getElementById("NewArrivals").appendChild(mainouterDiv);
        for (k= 0; k <NewArrivalData.length; k++) 
        {
            outerDiv = document.createElement("DIV");
            outerDiv.setAttribute("id", "NewArrivalouterDiv"+k);
            outerDiv.setAttribute("class", "container shadow my-4 card-hover-effect card-hover-effect:hover bg-white  rounded col-9 col-sm-12 col-md-5 col-lg-3 col-xl-3");
            mainouterDiv.appendChild(outerDiv);
            for (p = 0; p <1; p++) 
            {
            imgDivNewArrival= document.createElement("DIV");
            imgDivNewArrival.setAttribute("id", "outerimgDivNewArrival"+j);
            imgDivNewArrival.setAttribute("class", "row px-3 py-3");
            outerDiv.appendChild(imgDivNewArrival);
        
            imgDiv = document.createElement("img");
            imgDiv.setAttribute("id", "NewArrivalimgDiv"+k);
            imgDiv.setAttribute("class", "row cardimg");
            imgDiv.src = Utils.Path +"images/"+NewArrivalData[k].Img;
            imgDivNewArrival.appendChild(imgDiv); 
    
            textDiv = document.createElement("DIV");
            textDiv.setAttribute("id", "NewArrivaloutertextDiv"+k);
            textDiv.setAttribute("class", " row TitleText px-3 py-3");
            outerDiv.appendChild(textDiv);
            document.getElementById("NewArrivaloutertextDiv"+k).innerHTML= NewArrivalData[k].cardFooterText;
            }
        }
        flag=false;
    }
    switch(cardNumber)
    {
        case 0: $(".fontCls").css("font-size","21px") ;break;
        case 1: $(".fontCls").css("font-size","16px");break;
        case 2: $(".fontCls").css("font-size","14px");break;
    }
}
Energypage = function (div)
{
    CardNameArray.push(div.getAttribute("Title"));
    DisplayPage();
    cardNumber++;
    $('#Homepage').css('background-image',"url(" + Utils.Path +"images/energy-background.png"); 
    document.getElementById("mainBody").innerHTML = " ";
    document.getElementById("NavBar").style.display = "none";
    document.getElementById("NewArrivals").style.display = "none";
    document.getElementById("SelectLanguage").style.visibility = "hidden";
    init(AppData[cardNumber].Energydata,AppData[cardNumber].Energydata.length,"Electricitypage(this)");
}
Electricitypage = function (div)
{
    CardNameArray.push(div.getAttribute("Title"));
    DisplayPage();
    cardNumber++;
    document.getElementById("mainBody").innerHTML = " ";
    init(AppData[cardNumber].Electricitydata,AppData[cardNumber].Electricitydata.length,"Displayvideoinfopage(this)");
    CardNameArray.push(AppData[cardNumber].Energydata.Text);
    DisplayPage();
}
Displayvideoinfopage = function (div)
{
    CardNameArray.push(div.getAttribute("Title"));
    DisplayPage();
    downloadpdf=div.getAttribute("Src")
    document.getElementById("viewCatagary").style.display = "none";
    document.getElementById("NavBar").style.display = "none";
    document.getElementById("NewArrivals").style.display = "none";
    document.getElementById("LastPage").style.display = "block";
    $('#LastPage').css('background-image',"url(" + Utils.Path +"images/energy-background.png"); 
    $('#videotitle').css('text-transform',"capitalize"); 
    document.getElementById("videoimg").src=Utils.Path +"images/"+div.getAttribute("Img"); 
    document.getElementById("videotitle").innerHTML=div.getAttribute("Title");
    document.getElementById("videoinfo").innerHTML=div.getAttribute("Info");
    var words=div.getAttribute("Src");
    var n = words.split(".");
    var LastWord= n[n.length - 1];
    if(LastWord=="mp4"){
    document.getElementById("fullscreen-btn").style.display = "none";
    document.getElementById("download-btn").style.display = "none";
    document.getElementById("pdf").style.display = "none";
    document.getElementById("DiaplayVideo").src=div.getAttribute("Src");
     }
     else{
    $('#videoInfoDiv').css('margin-top',"49px");
     document.getElementById("DiaplayVideo").style.display = "none";
     document.getElementById("fullscreen-btn").style.display = "block";
     document.getElementById("download-btn").style.display = "block";
     document.getElementById("pdf").style.display = "block";
     document.getElementById("pdf").src=div.getAttribute("Src");
     }
}
DisplayPage = function (functionName)
{
    document.getElementById("Nextpage").innerHTML = " ";
    for (j = 0; j <CardNameArray.length; j++) 
    {
        var Nextpagediv = document.createElement("DIV");
        Nextpagediv.setAttribute("id", "Nextcarddiv"+j);
        Nextpagediv.setAttribute("class", "NextpageCls px-3");
        Nextpagediv.setAttribute("onclick", ""+functionName);
        document.getElementById("Nextpage").appendChild(Nextpagediv);
        document.getElementById("Nextcarddiv"+j).innerHTML= CardNameArray[j];
        if(j<CardNameArray.length-1){
            let i = document.createElement("i");
            i.innerHTML = '<i class="fa fa-arrow-right">';
            document.getElementById("Nextpage").appendChild(i)
        }
        if(j==CardNameArray.length-1)
            Nextpagediv.setAttribute("class", "NextpageCls fw-bold px-3");
    }
}
function openFullscreen() {
    var pdfSrcFile=document.getElementById("pdf");
    if (pdfSrcFile.requestFullscreen) {
        pdfSrcFile.requestFullscreen();
    } else if (pdfSrcFile.webkitRequestFullscreen) { 
        pdfSrcFile.webkitRequestFullscreen();
    } else if (pdfSrcFile.msRequestFullscreen) { 
        pdfSrcFile.msRequestFullscreen();
    }
  }
function downloadPDF()
{
    // window.location = downloadpdf;
    window.open(downloadpdf, '_blank');
}