﻿//---- Lightbox ----
jQuery(document).ready(function ($) { $('.lightbox').lightbox(); });

//---- Items List ----
$(document).ready(function () {
    $('.ImgInfo100').mouseenter(function (e) {
        $(this).children('a').children('img').animate({ height: '130', left: '-15', top: '-15', width: '130' }, 100);
        $(this).children('a').children('span').fadeIn(200);
    }).mouseleave(function (e) {
        $(this).children('a').children('img').animate({ height: '100', left: '0', top: '0', width: '100' }, 100);
        $(this).children('a').children('span').fadeOut(200);
    });
});

//---- Product Info ----
$(document).ready(function () {
    $('.ImgInfoWrap130').mouseenter(function (e) {
        $(this).children('a').children('img').animate({ height: '160', left: '-15', top: '-15', width: '160' }, 100);
        $(this).children('a').children('span').fadeIn(200);
    }).mouseleave(function (e) {
        $(this).children('a').children('img').animate({ height: '130', left: '0', top: '0', width: '130' }, 100);
        $(this).children('a').children('span').fadeOut(200);
    });
});

//---- Zoom Wrap 130 ----
$(document).ready(function () {
    $('.ImgZoomWrap130').mouseenter(function (e) {
        $(this).children('a').children('img').animate({ height: '160', left: '-15', top: '-15', width: '160' }, 100);
        $(this).children('a').children('span').fadeIn(200);
    }).mouseleave(function (e) {
        $(this).children('a').children('img').animate({ height: '130', left: '0', top: '0', width: '130' }, 100);
        $(this).children('a').children('span').fadeOut(200);
    });
});

//---- Select Fields ----
var openSelect = null;
$(function () {
    $("select.SelectField").each(function () {
        var i = $(this);
        var list = [];
        var label = "";
        i.children().each(function () {
            var tagName = String($(this)[0].tagName).toUpperCase();
            if (tagName == "OPTION") {
                list.push($(this));
            } else if (tagName == "OPTGROUP") {
                var subList = { label: $(this).attr("label"), children: $(this).children() };
                list.push(subList);
            }
        });

        var sName = $(this).attr("name");
        var html = "<div class=\"SelectField span-5\" >";
        html += "<input type=\"hidden\" name=\"" + sName + "\" value=\"" + list[0].val() + "\" />";
        html += "<div class=\"label\" ></div>";
        html += "<div class=\"button\" ><img src=\"../../../styles/default/common/webforms/select/arrow.png\" width=\"16\" height=\"16\" /></div>";
        html += "<div class=\"list hide\" >";

        for (var node in list) {
            if (list[node].label != undefined) {

                html += "<div class=\"optgroup span-5 last\" >" + list[node].label + "</div>";
                list[node].children.each(function () {
                    var selected = "";
                    if ($(this).attr("selected")) {
                        selected = "selected=\"selected\"";
                        label = $(this).html();
                    }
                    html += "<div class=\"option span-5 last\" " + selected + " val=\"" + $(this).val() + "\">" + $(this).html() + "</div>";
                });

            } else {

                var selected = "";
                if (list[node].attr("selected")) {
                    selected = "selected=\"selected\"";
                    label = list[node].html();
                }
                html += "<div class=\"option span-5 last\" " + selected + " val=\"" + list[node].val() + "\">" + list[node].html() + "</div>";
            }
        }

        html += "</div>";
        html += "</div>";
        html = $(html);
        i.replaceWith(html);

        html.data("state", "close");

        list = html.children(".list");

        list.hide();
        html.data("state", "close");

        // Try to get selected
        if (!label) {
            label = list.children().first().html();
        }
        list.children(".option").last().addClass("bottom");
        html.children(".label").html(label);
        list.children(".option").click(function () {
            html.children("input[name='" + sName + "']").val($(this).attr("val"));
            html.children(".label").html($(this).html());
        });
        html.click(function (event) {
            if ($(this).data("state") == "close") {
                $(this).children(".button").addClass("active");
                list.slideDown(125, function () {
                    html.data("state", "open");
                });
            }
        });
        $(document).click(function (event) {
            if (html.data("state") == "open") {
                $(html).children(".button").removeClass("active");
                list.hide();
                html.data("state", "close");
            }
        });
    });
});
