﻿var cssLink = top.document.createElement("link");
cssLink.setAttribute("rel", "Stylesheet");
cssLink.setAttribute("type", "text/css");
cssLink.setAttribute("href", "HomeGallery/css/global.css");
top.document.getElementsByTagName("head")[0].appendChild(cssLink);


LoadScript("HomeGallery/js/jquery.corner.js");
LoadScript("HomeGallery/js/slides.min.jquery.js");


function LoadScript(url) {
    document.write('<scr' + 'ipt type="text/javascript" src="' + url + '"><\/scr' + 'ipt>');
}

jQuery(document).ready(function($) {

    var width = 0;
    var height = 0;

    width = ($("#hdnWidth").val());
    height = ($("#hdnHeight").val());

    var imageHeight = height - 18;
    var imageWidth = width - 8;



    var galleryData = "";

    $.ajax({
        type: "POST",
        url: "Default.aspx/GetAllImages",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(response) {
            var images = response.d;

            $.each(images, function(index, image) {


                galleryData += "<div class='slide'>";

                if (image.Url.length > 0)
                    galleryData += "<a href='" + image.Url.replace('"', '') + "' target='" + image.Target + "'>";
                else
                    galleryData += "<a href='#'>";

                if ($.browser.msie)
                    galleryData += "<div class='galleryImage' style='height:" + imageHeight + "px; width:" + imageWidth + "px;'> <img ";
                else
                    galleryData += "<img class='galleryImage' ";


                galleryData += " src='" + image.Path + "' alt='Dialight Home Page' height='" + imageHeight + "px' width='" + imageWidth + "px' />";

                if ($.browser.msie)
                    galleryData += "</div>";
                galleryData += "</a>";

                if (image.Description.length > 0) {
                    galleryData += "<div class='caption' >";

                    //                    if ($.browser.msie)
                    //                        galleryData += "style='opacity:.5'";

                    galleryData += "<div class='captionText'>" +  image.Description;
                    galleryData += "</div></div>";
                }
                galleryData += "</div>";

            });

            $('.slides_container').append(galleryData);

            $('#slides').slides({
                preload: true,
                preloadImage: 'HomeGallery/images/loading.gif',
                play: delay, //5000,
                pause: delay, //2500,
                hoverPause: true,
                animationStart: function(current) {

                    $('.caption').animate({
                        bottom: -35
                    }, 100);
                    if (window.console && console.log) {
                        // example return of current slide number
                        console.log('animationStart on slide: ', current);
                    };
                },
                animationComplete: function(current) {

                var val = $('.caption').text();
                    
                    $('.caption').animate({
                        bottom: 0
                    }, 200);
                    if (window.console && console.log) {
                        // example return of current slide number
                        console.log('animationComplete on slide: ', current);
                    };
                },
                slidesLoaded: function() {
                    $('.caption').animate({
                        bottom: 0
                    }, 200);
                }
            });

            $('.slides').css({
                height: height - 5,
                width: width
            });

            $('#slides_container').css({
                top: 0,
                height: height - 14,
                width: width - 4
            });

            $('.slides_control').css({
                height: height - 16,
                width: width - 6
            });

            $('#slide').css({
                height: height - 18,
                width: width - 8
            });

            $('.galleryImage').corner("top 15px");

            //$('.galleryImage').corner("top 15px").parent().css('padding', '1px').corner("top 17px");

            $('.navigation').css({
                height: 40,
                width: 28,
                opacity: 0.5
            });

            $('.navigation').bind('mouseover', function(e) {
                $(this).css({ opacity: 1 })
            })

            $('.prev').bind('mouseout', function(e) {
                $('.navigation').css({ opacity: .5 })
            })

            $('.next').bind('mouseout', function(e) {
                $('.navigation').css({ opacity: .5 })
            })

            $('.slide').bind('mouseover mouseout', function(e) {
                $('.navigation').css({ opacity: (e.type == "mouseover") ? 1 : 0.5 })

            })

            if ($.browser.msie) 
            {
                $('.caption').css({
                'background': 'transparent',
                //99186821
                /* IE8 */
                '-ms-filter': 'progid:DXImageTransform.Microsoft.gradient(startColorstr=#a6000000,endColorstr=#a6000000)', 
                /* IE6 & 7 */
                'filter': 'progid:DXImageTransform.Microsoft.gradient(startColorstr=#a6000000,endColorstr=#a6000000)'  
                });
            }
        }
    });
});
