﻿jQuery.expr[':'].regex = function(elem, index, match) {
    var matchParams = match[3].split(','),
                validLabels = /^(data|css):/,
                attr = {
                    method: matchParams[0].match(validLabels) ?
                                matchParams[0].split(':')[0] : 'attr',
                    property: matchParams.shift().replace(validLabels, '')
                },
                regexFlags = 'ig',
                regex = new RegExp(matchParams.join('').replace(/^\s+|\s+$/g, ''), regexFlags);
    return regex.test(jQuery(elem)[attr.method](attr.property));
}

$(document).ready(function () {


    $('#slideshow').cycle({
        fx: 'fade',
        speed: 5500
    });


    $("input[type='image'][src='pictures/cart.png']").click(function () {
        $("input[type='image'][alt='ShopCart']").hide()
                    .animate({ opacity: 'show' }, 'fast')
                    .animate({ opacity: 'hide' }, 'fast')
                    .animate({ opacity: 'show' }, 'fast')
                    ;

        $(this).parent().parent().find("img:regex(src,winery.*)")
                    .animate({ opacity: 'hide', left: "+=640px", top: "-=200px", height: "-=150px", width: "-=50px" }, 'fast');

    });

    $("input[type='image'][src='pictures/cart.png'][alt='WeekCart']").click(function () {
        $("img[alt='WeekWine']")
                    .animate({ opacity: 'hide', left: "+=640px", top: "-=200px", height: "-=150px", width: "-=50px" }, 'fast');
    });


    $("input[type='text'][title='Počet kusů']").click(function () {
        $("input[type='submit'][title='Aktualizovat']").hide()
                    .animate({ opacity: 'show' }, 'fast')
                    .animate({ opacity: 'hide' }, 'fast')
                    .animate({ opacity: 'show' }, 'fast');
    });

    $("span[title='Zaškrtnout'] > input[type='checkbox']").click(function () {

        if ($(this).attr('checked')) {
            $("input[type='submit'][title='Vymazat']").hide()
                        .animate({ opacity: 'show' }, 'fast')
                        .animate({ opacity: 'hide' }, 'fast')
                        .animate({ opacity: 'show' }, 'fast');
        }

    });


    var $tooltip = $('#tooltip');

    var positionTooltip = function (event) {
        var tPosX = event.pageX;
        var tPosY = event.pageY;
    };

    var showTooltip = function (event) {

        positionTooltip(event);
        var tPosX = event.pageX;
        var tPosY = event.pageY;
    };

    var hideTooltip = function (event) {
        $tooltip.fadeOut("fast");
    };


    $("span:regex(id, ctl00_ContentPlaceHolder1_gvCart_.*) > span[id='cart_item']").hover(showTooltip, hideTooltip)
            .mousemove(positionTooltip)
            .hover(function () {
                $(this).css({ 'font-weight': 'bold' });
            }, function () {
                $(this).css({ 'font-weight': 'normal' });
            })
});

function postBackByObject(mEvent) {
    var o;
    // Internet Explorer    
    if (mEvent.srcElement) {
        o = mEvent.srcElement;
    }
    // Netscape and Firefox
    else if (mEvent.target) {
        o = mEvent.target;
    }
    if (o.tagName == "INPUT" && o.type == "checkbox") {
        __doPostBack("", "");
    }
}
