$(document).ready(function(){
    self.onerror = function() { return true; }
	Cufon.replace('span.menuItemText', {
		fontFamily : 'anivers-regular',
		textShadow : '1px 1px #063e5e'
	});
    $("input#topSearch").focus(function() {
        if ($(this).val() == "Search")
            $(this).val("");
    });
    $("input#topSearch").blur(function() {
        if ($(this).val() == "")
            $(this).val("Search");
    });
    jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
        return -c * ((t=t/d-1)*t*t*t - 1) + b;
    };

    $("a.registerTop").colorbox({width:"647", height:"414", iframe:true, onClosed: function(){
        $("div.youtubeVideoContainer").show();}});

    $("a.registerTop").click(function(){
        $("div.youtubeVideoContainer").hide();
    });

    $("input#fakePass").focus(function(){
        $(this).hide();
        $("input#realPass").show();
        $("input#realPass").focus();
    });
    $("input#realPass").blur(function(){
        if ($(this).val()==""){
            $(this).hide();
            $("input#fakePass").show();
        }
    });
    $("input#realEmail").focus(function(){
        if ($(this).val() == "Email"){
            $(this).val("");
        }
    });
    $("input#realEmail").blur(function(){
        if ($(this).val()==""){
            $(this).val("Email");
        }
    });

    $("input#fake_Pass").focus(function(){
        $(this).hide();
        $("input#real_Pass").show();
        $("input#real_Pass").focus();
    });
    $("input#real_Pass").blur(function(){
        if ($(this).val()==""){
            $(this).hide();
            $("input#fake_Pass").show();
        }
    });
    $("input#real_Email").focus(function(){
        if ($(this).val() == "Email"){
            $(this).val("");
        }
    });
    $("input#real_Email").blur(function(){
        if ($(this).val()==""){
            $(this).val("Email");
        }
    });

    makeVideoRelations();

//    $('div.itemULContainer').serialScroll({
//            items:'li',
//            prev:'a.butLeft',
//            next:'a.butRight',
//            offset:-10,
//            start:0,
//            duration:500,
//            force:true,
//            stop:true,
//            lock:true,
//            cycle:true, //don't pull back once you reach the end
//            easing:'easeOutQuart',
//            jump: false //click on the images to scroll to them
//        });
    $("input#topSearch").autocomplete({
        source: function(request, response) {
            $.ajax({
                url: URL_SITE + "index.php?action=productAjaxQuickSearchSuggest",
                dataType: "json",
                data: {
                    limit: 10,
                    keywords: request.term
                },
                success: function(data) {
                    response(data);
                }
            });
        },
        minLength: 1,
        delay: 0,
        focus: function (event, ui) {
            return false;
        }
    });
});

function makeVideoRelations()
{
    $("a.roundBut").mouseover(function(){
        $("img#butImg", $(this)).attr("src", URL_SITE + "templates/frontend/images/videolistpaginationselbg.png");
    });
    $("a.roundBut").mouseout(function(){
        $("img#butImg").attr("src", URL_SITE + "templates/frontend/images/videolistpaginationbg.png");
    });
    $("a.roundBut").click(function(){
        $("div.effectiveVideos").html("");
        $("div#loadingBarVideos").show();
        var page = $(this).attr("rel");
            $.ajax({
                url: URL_SITE + "index.php?action=pageAjaxGetVideosList&page=" + page,
                dataType: "json",
                success: function(data) {
                    $("div#loadingBarVideos").hide();
                    $("div.effectiveVideos").html(data.list);
                    $("div.effectivePaging").html(data.paging);
                    $("a.ytLink").each(function(){
                        $(this).attr("id", "");
                    });
                    $("a.video_"+currentVideo).attr("id", "sel");
                    makeVideoRelations();
                }
            });
        return false;
    });
    $("a.ytLink").click(function(){
            var id = $(this).attr("rel");
            currentVideo = id;
            $("div#loadingBar").show();
            $("div.youtubeVideo").html("");
            $.ajax({
                url: URL_SITE + "index.php?action=pageGetYoutubeVideo&id="+id,
                success: function(data) {
                    $("div.youtubeVideo").html(data);
                    $("a.ytLink").each(function(){
                        $(this).attr("id", "");
                    });
                    $("a.video_"+id).attr("id", "sel");
                    $("div#loadingBar").hide();
                }
            });
            return false;
    });
}
