function LoadData() {
    $("#scriptdiv").load("GetSlideShowImages.aspx");
    
}
 var ProductCod;
var TypeArr = new Array();

var industryIndex =0;    
     
var imgIndex1 = 0;
 var totalImages=0;
var imgIndex = 0;
 var imgPrevIndex = 0;
        var TypeCounter = 0;
        var runSlideShow = 0;
        var preCount = 0;
        
        function slideSwitch(dir) {
      
        if(runSlideShow==0)
           {
           
            var $active = $('#slideshow IMG.active');
            isSourceSet = false;
            if ($active.length == 0)
                $active = $('#slideshow IMG:last');
            if (dir == 1) {
                var $next = $active.next().length ? $active.next() : $('#slideshow IMG:first');
                imgIndex = $active.next().length ? imgIndex + 1 : 0;
                imgPrevIndex++;
            }
            else {
                  var $next = $active.prev().length ? $active.prev() : $('#slideshow IMG:last');
                 imgIndex = $active.prev().length ? imgIndex - 1 : totalImages - 1;
                imgPrevIndex--;
            }           
           if(imgPrevIndex<0 )//z&& TypeArr.length>1)
           {          
                document.getElementById('slideshow').innerHTML = '<img src="/images/slideshowloading.gif" class="active" />';
                window.document.getElementById('imgDivBig').src = '/images/slideshowloading2.gif' ;
                imgPrevIndex = 0;
                TypeCounter--;                               
                //alert(TypeCounter);
                if(TypeCounter<0)
                {
                     industryIndex --;
                            
                     if (industryIndex <0)
                        industryIndex = industryIds.length-1;
                            
                        TypeCounter = TypeArr.length -1;        
                         preCount=0;
                
                      LoadBasic(industryIds[industryIndex ], IndustryNames[industryIndex ], firstTypeNames[industryIndex ]);
                          return;
                }
                else
                {
                    preCount = 0;
                }
                
               var typeCount = TypeArr[TypeCounter]; 
               //alert(typeCount);
               runSlideShow = 1;                
               GetImageByProductIdandTypeNew(ProductCod,typeCount);
               //PageMethods.GetImageByProductIdandType(ProductCod, typeCount, cbGetImageByProductIdandType);
              
           }
           if(imgPrevIndex>=totalImages )//z&& TypeArr.length>1)
           {    
                preCount = 0;
                document.getElementById('slideshow').innerHTML = '<img src="/images/slideshowloading.gif" class="active" />';
                window.document.getElementById('imgDivBig').src = '/images/slideshowloading2.gif' ;
                if(TypeCounter >= TypeArr.length - 1)        
                {
                     industryIndex ++;
                     if (industryIndex == industryIds.length)
                            industryIndex =0;
                
                      LoadBasic(industryIds[industryIndex ], IndustryNames[industryIndex ], firstTypeNames[industryIndex ]);
                      return;
                }
                
                imgPrevIndex = 0;
                TypeCounter = TypeCounter + 1;
                var val= TypeArr[TypeCounter]; 
                val = TypeArr[TypeCounter]; 
                val = TypeArr[TypeCounter]; 
                runSlideShow = 1;         
                  GetImageByProductIdandTypeNew(ProductCod,val);                               
               // PageMethods.GetImageByProductIdandType(ProductCod, val, cbGetImageByProductIdandType);
           }      
           
            try
            {
            //window.document.getElementById('imgDivBig').src = '/images/slideshowloading2.gif' ;//  $('#imgDivBig').attr('src','/images/slideshowloading.gif');             
           $('#imgBig').attr('src', $("#slideshow").children().eq(imgIndex)[0].src.replace('small.png', 'big.png'));
            //$('#img1').attr('src', $("#slideshow").children().eq(imgIndex)[0].src.replace('small.png', 'big.png'));
            //$('#imgDivBig').attr('src', $("#slideshow").children().eq(imgIndex)[0].src.replace('small.png', 'big.png'));
             }
             catch(e)
             {
             
             }
            
       $active.addClass('last-active');
//z           if(totalImages>1)
           {      
            
             $next.css({ opacity: 'hide' })
            .addClass('active')
            .animate({ opacity: 'show' }, 1000, function() { $active.removeClass('active last-active'); });
            
            }
            
          }     
       }
       
       
       
//function slideSwitchold(dir) {

//    var $active = $('#slideshow IMG.active');

//    if ($active.length == 0)
//        $active = $('#slideshow IMG:last');
//    if (dir == 1) {
//        var $next = $active.next().length ? $active.next() : $('#slideshow IMG:first');
//        imgIndex = $active.next().length ? imgIndex + 1 : 0;
//        
//    }
//    else
//     {
//        var $next = $active.prev().length ? $active.prev() : $('#slideshow IMG:last');
//        imgIndex = $active.prev().length ? imgIndex - 1 : totalImages - 1;
//    }

//    $('#imgDivBig').attr('src', $("#slideshow").children().eq(imgIndex)[0].src.replace('small.png', 'big.png'));
//    
//    $active.addClass('last-active');
//   
//   if(totalImages>1)
//    $next.css({ opacity: 'hide' })
//            .addClass('active')
//           .animate({ opacity: 'show' }, 1000, function() { $active.removeClass('active last-active'); });
//            
//}

function slideSwitch1(dir) {

    var $active = $('#divProduct div.active');
    if ($active.length == 0)
        $active = $('#divProduct div:last');
    if (dir == 1) {
        var $next = $active.next().length ? $active.next() : $('#divProduct div:first');
        imgIndex1 = $active.next().length ? imgIndex1 + 1 : 0;
    }
    else {

        var $next = $active.prev().length ? $active.prev() : $('#divProduct div:last');
        imgIndex1 = $active.prev().length ? imgIndex1 - 1 : totalImages1 - 1;
    }
    for (var count = 0; count < totalImages1; count++) {
        $('#ProDiv' + count).css('display', 'none');
    }
    $('#ProDiv' + imgIndex1).css('display', 'inline');
    $active.addClass('last-active');
    $next.css({ opacity: 0.0 })
                    .addClass('active')
                    .animate({ opacity: 1.0 }, 1000, function() { $active.removeClass('active last-active'); });
}
// ---------------------------------- End Script for Types -----------------------------------------
var imgIndex2 = 0;

function slideSwitch2(dir) {
    var $active = $('#divType div.active');
    if ($active.length == 0)
        $active = $('#divType div:last');
    if (dir == 1) {

        var $next = $active.next().length ? $active.next() : $('#divType div:first');
        imgIndex2 = $active.next().length ? imgIndex2 + 1 : 0;
    }
    else {

        var $next = $active.prev().length ? $active.prev() : $('#divType div:last');
        imgIndex2 = $active.prev().length ? imgIndex2 - 1 : totalImages2 - 1;
    }
    for (var count = 0; count < totalImages2; count++) {
        $('#TypeDiv' + count).css('display', 'none');
    }
    $('#TypeDiv' + imgIndex2).css('display', 'inline');
    $active.addClass('last-active');
    $next.css({ opacity: 0.0 })
                    .addClass('active')
                    .animate({ opacity: 1.0 }, 1000, function() { $active.removeClass('active last-active'); });
}
// ---------------------------------- End Script for Types -----------------------------------------
function ShowModalGeneralizedCaller() {
    var imgPath = 'imgDiv' + 1;
    ShowModalGeneralized(imgPath);
}
function hidemodalgeneralizedcaller() {
    var imgPath = 'imgDiv' + 1;
    hidemodalgeneralized(imgPath);
}
function ShowModalGeneralized(divid) {

    //$("#GetNowDiv").show(500);
    //Get the screen height and width
    var maskHeight = $(document).height();
    var maskWidth = $(window).width();
    //Set height and width to mask to fill up the whole screen
    $('#mask').css({ 'width': maskWidth, 'height': maskHeight });

    //transition effect
    $('#mask').fadeIn(500);
    $('#mask').fadeTo("slow", 0.8);

    //Get the window height and width
    var winH = $(window).height();
    var winW = $(window).width();

    //Set the popup window to center            
    //$("#" + divid).css('top', winH / 2 - $("#" + divid).height() / 2);
    //$("#" + divid).css('left', winW / 2 - $("#" + divid).width() / 2);
    //transition effect
    $("#" + divid).fadeIn(1000);
}
function hidemodalgeneralized(divid) {
    //transition effect
    $('#mask').fadeOut(500);
    $("#" + divid).fadeOut(500);
    //$("#imgDivBig").attr('src','/images/loading5.gif');
}
function ShowBigImage(srcA) {
    $('#imgDivBig').attr('src', '/images/slideshowloading2.gif');
    if (srcA != '' && srcA.indexOf("/images/slideshowloading.gif") == -1) {
        $('#imgDivBig').attr('src', srcA.replace('small.png', 'big.png').replace('small.png', 'BIG.png'));
    }
    ShowModalGeneralizedCaller();
}

function SetBigImage(src) {


    if (src.indexOf("/images/slideshowloading.gif") == -1) {
        //$('#imgDivBig').attr('src', src.replace('small.JPG','png/png.png'));
        $('#imgDivBig').attr('src', src.replace('small.png', 'big.png').replace('small.png', 'BIG.png'));
    }
}





var menu1_on = false;
var menu2_on = false;
var isSourceSet = false;

function ShowMenu1() {

}

function ShowMenu2() {
}

function GetImagesForProduct(productID, productName) 
{
    for (var i=0; i<industryIds.length; i++)
    {
        if (industryIds[i] == productID)
            industryIndex = i;
    }
   // industryIndex = industryIds.indexOf( productID );
    if (IsFromProduct == 1)
        window.location.href = '/our-design-product/' + productName.replace(' ', '-').replace(' ', '-').replace(' ', '-').replace(' ', '-').replace(' ', '-') + '.aspx';
    else {
        if (productName.length > 13)
            document.getElementById('spnProductName').innerHTML = productName.substr(0, 13) + '..';
        else
            document.getElementById('spnProductName').innerHTML = productName;

         ProductCod = productID;
        
       GetTypesArrayNew(productID);
        //PageMethods.TypesGet(productID, cbGetTypeArray);
      GetImagesByProductIDNew(productID);
        //PageMethods.GetImageByProduct(productID, cbGetImageByProductId);
        
        PageMethods.GetTypeDivByProductID(productID, cbGetTypeDivByProductID);
    }
}
function getXMLHttpRequest() 
{
    if (window.XMLHttpRequest) {
        return new window.XMLHttpRequest;
    }
    else {
        try {
            return new ActiveXObject("MSXML2.XMLHTTP.3.0");
        }
        catch(ex) {
            return null;
        }
    }
}
var oReq = getXMLHttpRequest();
var oReq1 = getXMLHttpRequest();
var oReq2 = getXMLHttpRequest();

function handler()
{
    if (oReq.readyState == 4 /* complete */) {
        if (oReq.status == 200) {
            cbGetTypeArray(oReq.responseText);
        }
    }
}
function GetImageByProductIdandTypeNew(pid,typid)
{

if (oReq2 != null) {
    oReq2.open("GET", "/GetImagesByProductIdandTypeId.aspx?pid="+pid+"&tid="+typid+"&p="+Math.random(), true);
    oReq2.onreadystatechange = cbGetImageByProductIdandTypeNew;
    oReq2.send("");
}
}
function cbGetImageByProductIdandTypeNew()
{
if (oReq2.readyState == 4 /* complete */) {
        if (oReq2.status == 200) {
            cbGetImageByProductIdandType(oReq2.responseText.split(','));
        }
    }
}
function GetImagesByProductIDNew(pid)
{

if (oReq1 != null) {
    oReq1.open("GET", "/GetImagesByProductId.aspx?pid="+pid+"&p="+Math.random(), true);
    oReq1.onreadystatechange = cbGetImagesByProductIDNew;
    oReq1.send("");
}
}

function cbGetImagesByProductIDNew()
{
    if (oReq1.readyState == 4 /* complete */) {
        if (oReq1.status == 200) {
            cbGetImageByProductId(oReq1.responseText.split('|'));
        }
    }
}

function GetTypesArrayNew(productID)
{

if (oReq != null) {
    oReq.open("GET", "/GetTypesArray.aspx?pid="+productID+"&p="+Math.random(), true);
    oReq.onreadystatechange = handler;
    oReq.send("");
}



  
}


function cbGetTypeArray(result)
            {    
                        
                imgPrevIndex = 0;
                TypeCounter = 0;
                runSlideShow = 0;
                preCount = 0;
                TypeArr = new Array();
                TypeArr = result.split(',');            
            }


function GetImagesForProductFirstTime(productID, productName) {

    if (productName.length > 13)
        document.getElementById('spnProductName').innerHTML = productName.substr(0, 13) + '..';
    else
        document.getElementById('spnProductName').innerHTML = productName;


GetTypesArrayNew(productID);
//  PageMethods.TypesGet(productID, cbGetTypeArray);

 GetImagesByProductIDNew(productID);
//PageMethods.GetImageByProduct(productID, cbGetImageByProductId);
PageMethods.GetTypeDivByProductID(productID, cbGetTypeDivByProductID);

}

function GetImagesForType(productId, typeId, typeName) {

    if (typeName.length > 13)
        document.getElementById('spnTypeName').innerHTML = typeName.substr(0, 13) + '..';
    else
        document.getElementById('spnTypeName').innerHTML = typeName;

GetImageByProductIdandTypeNew(productId,typeId);
    //PageMethods.GetImageByProductIdandType(productId, typeId, cbGetImageByProductIdandType);
}

var gresult;
function cbGetTypeDivByProductID(result) {
try
{
gresult=result;
    document.getElementById('type_count').value = result[1];
    document.getElementById('LoadType').innerHTML = '<table id="inner_TBL" border="0" align="center" cellpadding="8"><tr >' + result[0] + '</tr></table>';
    document.getElementById('img1').src = result[7];    
    //document.getElementById('LoadType').innerHTML = result;
    }
    catch(ex)
    {
    setTimeout('delayedcbGetTypeDivByProductID()',1000);
    }
}
function delayedcbGetTypeDivByProductID()
{
cbGetTypeDivByProductID(gresult);
}
var _r;
function cbGetImageByProductId(r)
{
_r = r;
 //  setTimeout("alert(_r[0]) ",1000); 
    setTimeout("delayedFunction()",1000);
}

function delayedFunction() 
{
var result = _r;
    try {
        if (result[3].length > 13)
            document.getElementById('spnTypeName').innerHTML = result[3].substr(0, 13) + '..';
        else
            document.getElementById('spnTypeName').innerHTML = result[3];
    }
    catch (ex) { }

    imgIndex = 0;
    totalImages = result[0];

    

    if (result[1] != '0')
        document.getElementById('slideshow').innerHTML = result[1];
    ShowMenu1();
    document.getElementById('img1').src = result[7];
    document.getElementById('imgBig').src = result[4];

    document.getElementById('imgBigDivLoad').innerHTML = result[5];
} 

function show() {

    document.getElementById('slideshow').style.display = "inline";
}
function cbGetImageByProductIdandType(result) {

var typename=result[3];
if (typename.length > 13)
        document.getElementById('spnTypeName').innerHTML = typename.substr(0, 13) + '..';
    else
        document.getElementById('spnTypeName').innerHTML = typename;
        
    imgIndex = 0;
    totalImages = result[0];

    if (result[1] == '0') {
    return;
        //window.self.location.href= '/our-design-product/Logo-Design.aspx'
    }

    document.getElementById('slideshow').innerHTML = result[1];
    ShowMenu2();

    document.getElementById('imgBig').src = result[4];
    document.getElementById('imgBigDivLoad').innerHTML = result[5];
    document.getElementById('img1').src = result[7];
    runSlideShow = 0;
}





var imgIndex1 = 0;

//var disablePrevious = 0;
//var disableNext = 0;
//var lastIndex = -10;

function slideSwitch1(dir) {

    var $active = $('#divProduct div.active');

    if ($active.length == 0)
        $active = $('#divProduct div:last');
    if (dir == 1) {

        var $next = $active.next().length ? $active.next() : $('#divProduct div:first');
        imgIndex1 = $active.next().length ? imgIndex1 + 1 : 0;

    }
    else {


        var $next = $active.prev().length ? $active.prev() : $('#divProduct div:last');
        imgIndex1 = $active.prev().length ? imgIndex1 - 1 : totalImages1 - 1;

    }
    for (var count = 0; count < totalImages1; count++) {
        $('#ProDiv' + count).css('display', 'none');
    }

    $('#ProDiv' + imgIndex1).css('display', 'inline');
    $active.addClass('last-active');
    $next.css({ opacity: 0.0 })
            .addClass('active')
            .animate({ opacity: 1.0 }, 600, function() { $active.removeClass('active last-active'); });
}
function ShowModalGeneralizedCaller() {
    var imgPath = 'imgDiv' + 1;
    ShowModalGeneralized(imgPath);
}
function hidemodalgeneralizedcaller() {
    var imgPath = 'imgDiv' + 1;
    hidemodalgeneralized(imgPath);
}
function ShowModalGeneralized(divid) {

    //$("#GetNowDiv").show(500);
    //Get the screen height and width
    var maskHeight = $(document).height();
    var maskWidth = $(window).width();
    //Set height and width to mask to fill up the whole screen
    $('#mask').css({ 'width': maskWidth, 'height': maskHeight });

    //transition effect
    $('#mask').fadeIn(500);
    $('#mask').fadeTo("slow", 0.8);

    //Get the window height and width
    var winH = $(window).height();
    var winW = $(window).width();

    //Set the popup window to center            
    //            $("#" + divid).css('top', winH / 2 - $("#" + divid).height() / 2);
    //            $("#" + divid).css('left', winW / 2 - $("#" + divid).width() / 2);
    //transition effect

    //$("#" + divid).fadeIn(1000);
    $('#imgDiv1').css({ 'width': '0%', 'height': '0%' });
    $('#imgDiv1').animate({ opacity: 1, width: "650px", height: "400px" }, 600, function() {
        // $('#imgDiv1').animate({ opacity: 1, width: "75%", height: "30%"}, 600, function() { 

        // $('#imgDiv1').animate({ opacity: 1, width: "100%", height: "100%"}, 900);
    });
}
function ShowModalGeneralized1(divid) {

    //$("#GetNowDiv").show(500);
    //Get the screen height and width
    var maskHeight = $(document).height();
    var maskWidth = $(window).width();
    //Set height and width to mask to fill up the whole screen
    $('#mask').css({ 'width': maskWidth, 'height': maskHeight });

    //transition effect
    $('#mask').fadeIn(500);
    $('#mask').fadeTo("slow", 0.8);

    //Get the window height and width
    var winH = $(window).height();
    var winW = $(window).width();

    //Set the popup window to center            
    //            $("#" + divid).css('top', winH / 2 - $("#" + divid).height() / 2);
    //            $("#" + divid).css('left', winW / 2 - $("#" + divid).width() / 2);
    //transition effect

    $("#" + divid).fadeIn(1000);
}
function hidemodalgeneralized1(divid) {
    //transition effect
    $('#mask').fadeOut(500);
    $("#" + divid).fadeOut(500);

}

function hidemodalgeneralized(divid) {
    //transition effect
    $('#mask').fadeOut(500);
    //$("#" + divid).fadeOut(500);
    $('#imgDiv1').animate({ opacity: 'hide', width: "350px", height: "250px" }, 900);

}

var zoom_timer;
function ZoomImage() {
    zoom_timer = setTimeout(function() {
        if (isSourceSet) {
            window.ShowBigImage($("#slideshow").children().eq(imgIndex)[0].src);
        }
        else {
            window.ShowBigImage('');
        }
        //

        //var tempPosition = window.parent.yPosition;
        var tempPosition = yPosition;

        tempPosition = tempPosition.replace('px', '');
        //window.parent.document.documentElement.scrollTop = tempPosition - 25;

        document.documentElement.scrollTop = tempPosition - 100;
    }, 1)
}
function ZoomImage_1() {
    if (isSourceSet) {

        window.ShowBigImage($("#slideshow").children().eq(imgIndex)[0].src);
    }
    else {
        window.ShowBigImage('');
    }
    var tempPosition = yPosition;
    tempPosition = tempPosition.replace('px', '');

    document.documentElement.scrollTop = tempPosition - 50;
}
function clear_zoom() {
    clearTimeout(zoom_timer);
}
//function SetSrcTag() {

//    isSourceSet = true;
//    try {
//        $("#slideshow").children().eq(imgIndex)[0].src = document.getElementById('img1').src;
//        window.SetBigImage($("#slideshow").children().eq(imgIndex)[0].src);
//    }
//    catch (e) {
//    }
//}

 function SetSrcTag()
        {
			setTimeout(function(){
				isSourceSet = true; 
				 $("#slideshow").children().eq(imgIndex)[0].src = document.getElementById('imgBig').src.replace('big.png','small.png');           
				window.SetBigImage($("#slideshow").children().eq(imgIndex)[0].src);     
			}, 500);
        }



var clearNextTimer;
var clearPreviousTimer;

function NextImgCaller() {
    clearNextTimer = setInterval("slideSwitch(\"1\")", 2500);
}

function PreviousImgCaller() {
    clearPreviousTimer = setInterval("slideSwitch(\"-1\")", 2500);
}
function NextImgCaller_1() {

    slideSwitch(1);
}

function PreviousImgCaller_1() {
    slideSwitch(-1);
}

function ClearImgNext() {
    try {

        clearTimeout(clearNextTimer);
    }
    catch (e) { }
}

function ClearPreviousImg() {
    try {
        clearTimeout(clearPreviousTimer);
    }
    catch (e) { }
}

var ZoomImgTimer;

function OpenBigImg() {
    ZoomImgTimer = setTimeout("ZoomImage()", 1000);
}
function ClearBigImgTimer() {
    try {
        clearTimeout(ZoomImgTimer);
    }
    catch (e) { }
}


var IsFromProduct = 0;
function LoadBasic(productid, productname, typename) {
ProductCod=productid;
    if (typename.length > 13)
        document.getElementById('spnTypeName').innerHTML = typename.substr(0, 13) + '..';
    else
        document.getElementById('spnTypeName').innerHTML = typename;
    GetImagesForProductFirstTime(productid, productname);
    PageMethods.GetTypeDivByProductID(productid, cbGetTypeDivByProductID);
}
function GetIndustries(TemplateSubdetailcode) {
    PageMethods.GetIndustriesMenuHTML(TemplateSubdetailcode, cbGetIndustriesMenuHTML)
}

var retryDone = false;

function cbGetIndustriesMenuHTML(result) {
    try
    {
        document.getElementById('spnProductName').innerText = result[0];
        document.getElementById('divProduct').innerHTML = result[1];
    }
    catch(ex)
    {
    if (!retryDone)
        window.setTimeout('cbGetIndustriesMenuHTML(new Array('+result[0]+','+ result[1]+'))',1000);
    retryDone = true;
    }
}
//Function to use 
//GetIndustriesMenuHTML(string templateDetailCode) //returns string[] {firstIndustryName, industryMenuHTML}


function SetSlideImageByType(divID, Type) {
    document.getElementById('slideshow').innerHTML = '';
    document.getElementById('slideshow').innerHTML = document.getElementById(divID).innerHTML;
    document.getElementById('TypeName').innerText = Type;
}
function LoadIframe() {
    document.getElementById('frameRight').src = '/AccountRequest.aspx';
}
function querySt(ji) {
    hu = window.location.search.substring(1);
    gy = hu.split("&");
    for (i = 0; i < gy.length; i++) {
        ft = gy[i].split("=");
        if (ft[0] == ji) {
            return ft[1];
        }
    }
}