// jQuery page load function

var $j = jQuery.noConflict();


$j(document).ready(function() {

    $j(function() {
        $j('ul.sf-menu').superfish({
            delay: 0,                            // one second delay on mouseout 
            animation: { height: 'show' },  // fade-in and slide-down animation 
            speed: 'fast',                          // faster animation speed 
            autoArrows: false,                           // disable generation of arrow mark-up 
            dropShadows: false                            // disable drop shadows 
        });
    });


    $j("ul#nav-accordian li.level0 h2 a").attr("href", "#");

    if ($j("ul#nav-accordian li.level0 h2 a.open").length == 0) {
        $j("ul#nav-accordian li.level0 h2 a:first").addClass("expanded").addClass("open").removeClass("collapsed").parent().parent().children("ul.level0").show().addClass("open");
    }

    $j("ul#nav-accordian li.level0 h2 a").click(function(e) {
        var $this = $j(this);

        if (!$this.hasClass("open")) {
            $j("ul#nav-accordian li.level0 ul.level0.open").slideUp().removeClass("open");
            $j("ul#nav-accordian li.level0 h2 a.open").removeClass("open");
            $this.addClass("expanded").addClass("open").removeClass("collapsed").parent().parent().children("ul.level0").slideDown().addClass("open");
            $j("ul#nav-accordian li.level0 h2 a").not(".open").removeClass("expanded").addClass("collapsed");
        }

        return false;
    });

    if (window.location.search.match("by=theme")) {
        $j("li.nav-shoppe h2 a:first").addClass("collapsed").removeClass("open").removeClass("expanded").parent().parent().children("ul.level0").hide().removeClass("open");
        $j("li.nav-themes h2 a:first").addClass("expanded").addClass("open").removeClass("collapsed").parent().parent().children("ul.level0").show().addClass("open");
    }

    $j(".popup-tutorial").click(function(e) {

        e.preventDefault();
        var href = $j(e.target).attr('href');
        if (href == undefined) {
            href = $j(e.target).parent().attr('href');
        }
        window.open(href, '', 'menubar=0,location=0,toolbar=0,width=1077,height=900');

    });

    $j(".gallery-tutorial").click(function(e) {

        e.preventDefault();
        var href = $j(e.target).attr('href');
        if (href == undefined) {
            href = $j(e.target).parent().attr('href');
        }
        window.open(href, '', 'menubar=0,location=0,toolbar=0,width=1077,height=900');

    });

    $j(".popup").click(function(e) {

        e.preventDefault();
        var href = $j(e.target).attr('href');
        if (href == undefined) {
            href = $j(e.target).parent().attr('href');
        }
        window.open(href, '', 'menubar=1,location=1,toolbar=1,width=1077,height=900');

    });

    $j("#close").click(function(e) {
        self.close();
    });

});
