﻿

jQuery.preloadImages = function() {
    lng = max_img;
    for (var i = 1; i <= lng; i++) {
        jQuery("<img>").attr("src", "Khiri-Image/Brand1_" + i + "_01_.jpg");
    }
    jQuery("<img>").attr("src", "Khiri-Image/Arrow-Left_1.jpg");
    jQuery("<img>").attr("src", "Khiri-Image/Arrow-Right_1.jpg");
}

//$.preloadImages("Khiri-Image/Brand1_1.jpg", "/path/to/image2.png",
//"some/image3.jpg");

//jQuery.preloadImages = function() {
//    for (var i = 0; i < arguments.length; i++) {
//        jQuery("<img>").attr("src", arguments[i]);
//    }
//}

var max_img = 0;
var mycarousel_itemList = [
    { idx: 1, url: 'Khiri-Image/Brand1_1.jpg', title: 'Khiri-DMC', link: 'DMC' },
    { idx: 2, url: 'Khiri-Image/Brand1_2.jpg', title: 'Khiri Voyages', link: 'Voyages' },
    { idx: 3, url: 'Khiri-Image/Brand1_3.jpg', title: 'Khiri Asia', link: 'Asia' },
    { idx: 4, url: 'Khiri-Image/Brand1_4.jpg', title: 'Khiri Gold', link: 'Gold' },
    { idx: 5, url: 'Khiri-Image/Brand1_5.jpg', title: 'Khiri Naga', link: 'Naga' },
    { idx: 6, url: 'Khiri-Image/Brand1_6.jpg', title: 'American Persuits', link: 'American' },
    { idx: 7, url: 'Khiri-Image/Brand1_7.jpg', title: 'Khiri Lotus', link: 'Lotus' },
    { idx: 8, url: 'Khiri-Image/Brand1_8.jpg', title: 'Khiri Reach', link: 'Reach' }
];

function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt) {
         max_img = mycarousel_itemList.length;
         var idx = carousel.index(i, max_img);
         carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[idx - 1], idx));
};

function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt)
{
    carousel.remove(i);

};

function mycarousel_getItemHTML(item, idx) {
    return '<a onmouseover="javascript:modal_pop(' + idx + ')" class="imgs"><img src="' + item.url + '" width="138" border="0" height="318" alt="' + item.title + '" /></a>';

    };


    jQuery(document).ready(function() {
        jQuery('#mycarousel').html('');
        jQuery('#mycarousel').jcarousel({
            wrap: 'circular',
            scroll: 1,
            auto: 4,
            itemVisibleInCallback: { onBeforeAnimation: mycarousel_itemVisibleInCallback },
            itemVisibleOutCallback: { onAfterAnimation: mycarousel_itemVisibleOutCallback }
        });

        jQuery.preloadImages();
        $("#boxcaption").css("background", "#000");
        $("#boxcaption").css("opacity", 0.7);

    });

gourl = function(url) { window.location = url; }

function getNextPrev(nidex) {
   //  modal_out();
   // for (ix = 1; ix <= (max_img); ix++) { $("#txt_" + ix).hide(1); }
    //window.setTimeout(function() {
   // modal_out(500);
    modal_pop(nidex)
  //  $("#block").unbind();
//}
   //  , 100);

}

var lst_idx  = '' ;
function modal_pop(idx) {

    $(this).dequeue();
    var max = max_img;

    var flsh = "<object type='application/x-shockwave-flash' data='index_flash/Index_Banner_" + mycarousel_itemList[idx - 1].link + "_715.swf' class='ind_flash' id='ind_flash' wmode='transparent' width='715' height='310'>"
		flsh += "<param name='movie' value='index_flash/Index_Banner_" + mycarousel_itemList[idx - 1].link + "_715.swf' />"
		flsh += "<param name='SCALE' value='exactfit' />"
		flsh += "<param name='wmode' value='transparent' />"
		flsh += "<param name='quality' value='high' />"
		flsh += "</object>";

	$("#flsh").html(flsh);
   // $("#block").attr("src", "");
    $("#block").attr("src", "Khiri-Image/Brand1_" + idx + "_01_.jpg");
   // $("#modal_lnk").bind("click",  function() { window.location = "goBands.aspx?idx=" + idx ; });
    $(".div_over").bind("click", function() { window.location = "goBands.aspx?idx=" + idx; });
     
    var idNext = (idx == max) ? 1 : idx + 1;
    var idPrev = (idx == 1) ? max : idx - 1;
    if (!($.browser.msie)) {
        $(".jcarousel-next").bind("click", function() { getNextPrev(idNext) });
        $(".jcarousel-prev").bind("click", function() { getNextPrev(idPrev) });
    }
    for (ix = 1; ix <= (max); ix++) {
        // $("#txt_" + ix).hide(1); 
       $("#txt_" + ix).css("display","none"); 
    }
    $("#txt_" + idx).css("display", "block")
   // $("#txt_" + idx).show(10); lst_idx = idx;
    $("#block").fadeIn(1200);
    $("#boxcaption").animate({ top: '-2px' }, { queue: 1, duration: 10 }).animate({ left: '204px' }, { queue: 0, duration: 1000 });


    clearlist();
    
    
//    if ($.browser.safari) {
//        $("#block").bind("mouseleave", function() { modal_out(); });
//    } else { // if opera
      //  $("#wrap").bind("mouseleave", function() { modal_out(); });
//    }

}

function clearlist() { $("#wrap").bind("mouseleave", function() { modal_out(900); }); }

function modal_out(minute) {
    //$("#boxcaption").dequeue();
    $("#boxcaption").animate({ left: '0px' }, { queue: 0, duration: minute }).dequeue();
    
    $("#flsh").html("");
    $(".jcarousel-next").unbind("click");
    $(".jcarousel-prev").unbind("click");
   // $("#modal_lnk").unbind("click");
   // $("#wrap").unbind("mouseleave");
    $("#block").fadeOut(minute-150); 
    
}
