$(document).ready(function(){
	$('ul.accordion').accordion({
		active: ".selected",
		autoHeight: false,
		header: ".opener",
		collapsible: true,
		event: "click"
	});
 //animate icons width
	var _defElemProd =null;
    var _activeElemProd = null;
    $('#nav li').each(function(){
        var _this = $(this);
        var _div = _this.find('div:eq(0)');
        _this.find('a').each(function(){
            if($(this).attr('href') == window.location.href && !$(this).parents('li:eq(0)').hasClass('active')){
                $(this).parents('li:eq(0)').addClass('active');
            };
        });
        if(_this.hasClass('active')){
            _div.width(343);
            _activeElemProd = _defElemProd = _div;
        }
        _this.mouseenter(function(){
            if(_activeElemProd) _activeElemProd.animate({width: 108},{duration: 300, queue: false, easing: 'linear'});
            _div.animate({width: 343},{duration: 300, queue: false, easing: 'linear',complete:function(){
                
            }});
        }).mouseleave(function(){
            _div.animate({width: 108},{duration: 300, queue: false, easing: 'linear',complete:function(){
                
            }});
			if(_defElemProd) _activeElemProd.animate({width: 343},{duration: 300, queue: false, easing: 'linear'});
        })
    })
});

function initPage()
{
	var nav = document.getElementById("nav");
	if (nav)
	{
		var nodes = nav.getElementsByTagName("li");
		for (var i = 0; i < nodes.length; i++)
		{
			nodes[i].onmouseover = function () 
			{
				if (this.className.indexOf("hover") == -1)
				{
					this.className += " hover";
				}
			}
			nodes[i].onmouseout = function ()
			{
				this.className = this.className.replace(" hover", "");
			}
		}
	}
}
if (window.attachEvent && !window.opera)
	window.attachEvent("onload", initPage);
/*add*/

$(window).bind('load',function(){
//popup
    var _ovrl = $('#popup-overlay').css({
        opacity:0,
        height: $('#popup-overlay').parent().height()
    });
	var _popup = $('.popup').each(function(i){
            var _id = this.id;
            $(this).addClass('ar'+i);
            $('.navigation-holder ul > li a').eq(i).attr('rel', _id);
        });
    var _t = null;
    $('.navigation-holder ul > li a').mouseenter(function(){
        var _rel = $(this).attr('rel');
        if(_rel){
            if($('#'+_rel).length) $('#'+_rel).show().mouseenter(function(){
                if(_t) clearTimeout(_t);
            }).mouseleave(function(){
                $('#'+_rel).hide();
                _ovrl.animate({opacity: 0}, {queue: false, duration: 300});
            });
            _ovrl.animate({opacity: 0.4}, {queue: false, duration: 300, complete: function(){
                
            }});
        }
    }).mouseleave(function(){
        var _rel = $(this).attr('rel');
        if(_rel){
            _t = setTimeout(function(){
                if($('#'+_rel).length) $('#'+_rel).hide();
                if(!_popup.filter(':visible').length) _ovrl.animate({opacity: 0}, {queue: false, duration: 300});
            },100);
        };
    });
})
