$(function() {
    var search_q = $("#search_q").val();

    $("#cmenu ul.sf-menu").superfish({
        animation: 		{
            height: 'show'
        },
        speed: 			200,
        delay: 			600,
        autoArrows:             false,
        dropShadows:            false
    });

    $("#search_q").click(function() {
        if(search_q == $(this).val()) {
            $(this).val('');
        }
    });

    $("#search_q").blur(function() {
        if($(this).val() == '') {
            $(this).val(search_q);
        }
    });

    $("a[rel^='gallery']").prettyPhoto({
        animationSpeed:'fast'
        ,
        slideshow:3000
    });


    // main action
    var actionOpen = $("#actionOpenContent");

    if (actionOpen.text()) {
        $.prettyPhoto.open('#actionOpenContent', '', '');
    } else {
        actionOpen = $("#actionOpenImage");
        if (actionOpen.text()) {
            $.prettyPhoto.open(actionOpen.text(), '', '');
        }
    }

});

function mycarousel_initCallback(carousel)
{
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

function isValidEmail(email){
    var RegExp = /^((([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+(\.([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+)*)@((((([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.))*([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.)[\w]{2,4}|(((([0-9]){1,3}\.){3}([0-9]){1,3}))|(\[((([0-9]){1,3}\.){3}([0-9]){1,3})\])))$/
    if(RegExp.test(email)){
        return true;
    }else{
        return false;
    }
}

function addUser() {
    var mail = $("#newslatter_mail").val();
    if(isValidEmail(mail)) {
        sendRequest('action=newsletter&flag=add&mail=' + mail);
    } else {
        alert_error('newsletter',LANG['user-added-novalid']);
    }
        
    return false;
}

$(function() {
    $('#banner-box .text').marquee('text').mouseover(function () {
        $(this).trigger('stop');
    }).mouseout(function () {
        $(this).trigger('start');
    }).mousemove(function (event) {
        if ($(this).data('drag') == true) {
            this.scrollLeft = $(this).data('scrollX') + ($(this).data('x') - event.clientX);
        }
    }).mousedown(function (event) {
        $(this).data('drag', true).data('x', event.clientX).data('scrollX', this.scrollLeft);
    }).mouseup(function () {
        $(this).data('drag', false);
    });
});
