(function()
    {
        var carparts_navigation = function(options)
        {
            this._options = jQuery.extend({               
                forms:  '#main_navigation form',
                dropdowns: '#main_navigation .dropdown',
                items: '#main_navigation a.naviHead'
            }, options);
            var self = this;
            jQuery(document).ready(function()
            {
                self.initialize();
                jQuery('div#left').removeClass('naviHidden');
            });

    
        }

        carparts_navigation.prototype = jQuery.extend(carparts_navigation.prototype,
        {
            initialize: function()
            {
                this._forms           = jQuery(this._options.forms);
                this._items           = jQuery(this._options.items);
                this._dropdowns       = jQuery(this._options.dropdowns);
                this._bindEvents();
                this._onLoad();
            },
            _onLoad: function()
            {


                if (navRootId !== '4829')
                {
                    jQuery.each(this._items, function(i, item)
                    {
                
                        if(jQuery.cookie(jQuery(item).attr('id')) == 'closed')
                        {
                            jQuery(item).addClass('closed');
                            jQuery(jQuery(item).attr('href')).hide();
                        }
                        
                        else
                        {
                            jQuery(jQuery(item).attr('href')).slideDown();
                        }
                  
                    });
                }
                // if current Product is in closed Menu, open it
                jQuery('li.navi1').each(function(){
                    if (jQuery(this).children('ul.child li a').hasClass('navact')) {
                       jQuery(this).parents('ul').slideDown();
                    }
                })

            },
            _bindEvents: function()
            {
                var self = this;
                this._forms.bind('submit', function(ev) {
                    ev.preventDefault()
                });

                //Haendler dropdown onchange functions
                this._dropdowns.bind('change', function(ev)
                {
                    var dropdown = ev.currentTarget;
       

                    window.location.href = jQuery.attr(dropdown, 'value');
                });
                this._items.bind('click keypress', function(ev)
                {
                    ev.preventDefault();
                    var invoker = this;


                    jQuery(jQuery.attr(this, 'href')).slideToggle(function()
                    {
         
                        if (navRootId !=='4829') {
                            jQuery(invoker).addClass('closed');
                            jQuery.cookie(jQuery(invoker).attr('id'), 'closed');
                        }
                        else          {
                            if (navRootId !=='4829') {
                                jQuery(invoker).removeClass('closed');
                                jQuery.cookie(jQuery(invoker).attr('id'), 'open');
                            }
                        }
                    });
                });
            }
        });
        new carparts_navigation();



        
        jQuery(document).ready(function() {

        // fix incorrect outbound links missing http or malfunctioned
jQuery('a[href^="www."]').each(function(){
	var check = jQuery(this).attr('href');
	var updated = 'http://' + check;
	jQuery(this).attr('href',updated);
});



       //christmas special...remove in 2012
jQuery('a[href*="oxfam."]').each(function(){
	var check = jQuery(this).attr('href');
	var updated = 'http://' + check;
	jQuery(this).attr('href',updated);
});



// fix broken
jQuery('a[href^="/https"]').each(function(){
	var check = jQuery(this).attr('href');
	var updated = check.replace('/https', 'https');
	jQuery(this).attr('href',updated);
});
jQuery('a[href^="maps."]').each(function(){
	var check = jQuery(this).attr('href');
	var updated = 'http://' + check;
	jQuery(this).attr('href',updated);
});





        
        var isitMT = jQuery('#ajaxUpdate .wk_inhalt p:first').text();
        Wkorb = jQuery('#warenkorb');

         // TODO: optimize this
        //if (!isitMT == 'Der Warenkorb ist leer.' && Wkorb:hidden.length) {
          jQuery('#warenkorb').css('display','block');

        //}


          // Warenkorb AddTo-FX

          var update;

          function loadCart() {
              update = jQuery(this).attr('href'); 
 		window.location.href= update;
          }

          jQuery('.buttonCart a').click(function(event){          // detail Page
            jQuery('#warenkorb').css('display','block');
            update = jQuery(this).attr('href');  
            event.preventDefault();         
            jQuery('img.produktImage').clone().addClass('shopFX').appendTo('#MainInfo p.produktImage').fadeTo(0.5).animate({'top':'150px','left':'640px','width':'35%','height':'35%'},900,'easeInOutQuad',function(){
  jQuery('.wk_inhalt').fadeTo(300,0.3);
  jQuery('#warenkorb').append('<div class="ajaxLoader"></div>');
  jQuery('.ajaxLoader').fadeIn(400);  

  jQuery.ajax({
    url: update,
    success: function(data) {    
      currentPage = window.location.href;
      jQuery('#warenkorb #ajaxUpdate').load(currentPage+' #ajaxUpdate .wk_inhalt',function(){
      jQuery('.ajaxLoader').fadeOut(400,function(){jQuery('.ajaxLoader').remove();});
      jQuery('span.wk_summe').fadeTo(300,0.2,function(){
       jQuery('.priceUp').load(currentPage+' .priceUp span.wk_summe');
      });

      });  
    }
});//end ajax

  return false;

}).fadeOut(500);

          });


          jQuery('a.shopItLink').click(function(event){          // overview Page
            jQuery('#warenkorb').css('display','block');
            update = jQuery(this).attr('href');    
            var cartOffset = jQuery("#warenkorb").position();
            var clientOffset = jQuery(this).position();
            var imgTD = jQuery(this).parents('.artView').find('.artImgs');
            event.preventDefault();
            jQuery(this).parents('.artView').find('.artImg').clone().addClass('shopFX').appendTo('#container').css({'top': clientOffset.top-230,'left': clientOffset.left-55}).fadeTo(0.5).animate({'top': cartOffset.top+5,'left': cartOffset.left+63,'width':'35px','height':'35px'},900,'easeInOutQuad',function(){
    
  jQuery('.wk_inhalt').fadeTo(300,0.3);
  jQuery('#warenkorb').append('<div class="ajaxLoader"></div>');
  jQuery('.ajaxLoader').fadeIn(400);  

  jQuery.ajax({
    url: update,
    success: function(data) {    
      currentPage = window.location.href;
      jQuery('#warenkorb #ajaxUpdate').load(currentPage+' #ajaxUpdate .wk_inhalt',function(){
      jQuery('.ajaxLoader').fadeOut(400,function(){jQuery('.ajaxLoader').remove();});
      jQuery('span.wk_summe').fadeTo(300,0.2,function(){
      jQuery('.priceUp').load(currentPage+' .priceUp span.wk_summe');
      });

      });  
    }
});//end ajax

  return false;

}).fadeOut(500);
     
          });


          jQuery('.prl_tabelle td.prl_nr a.shopThis').click(function(event){          // overview Page Artikel breit
            jQuery('#warenkorb').css('display','block');
            update = jQuery(this).attr('href'); 
            var cartOffset = jQuery("#warenkorb").position();
            var clientOffset = jQuery(this).position();
            var imgTD = jQuery(this).parents('.prl_tabelle').find('.prl_beschreibung');
            event.preventDefault();
            jQuery(this).parents('.prl_tabelle').find('.prl_beschreibung a img').clone().addClass('shopFX').appendTo('#container').css({'top': clientOffset.top,'left': clientOffset.left}).fadeTo(0.5).animate({'top': cartOffset.top+10,'left': cartOffset.left+40,'width':'40px','height':'28px'},900,'easeInOutQuad',function(){

jQuery('.wk_inhalt').fadeTo(300,0.3);
  jQuery('#warenkorb').append('<div class="ajaxLoader"></div>');
  jQuery('.ajaxLoader').fadeIn(400);  

  jQuery.ajax({
    url: update,
    success: function(data) {    
      currentPage = window.location.href;
      jQuery('#warenkorb #ajaxUpdate').load(currentPage+' #ajaxUpdate .wk_inhalt',function(){
      jQuery('.ajaxLoader').fadeOut(400,function(){jQuery('.ajaxLoader').remove();});
      jQuery('span.wk_summe').fadeTo(300,0.2,function(){
      jQuery('.priceUp').load(currentPage+' .priceUp span.wk_summe');
      });

      });  
    }
});//end ajax

  return false;


}).fadeOut(500);
            });

          
           

            //Aktuelles in Header ausgeben (Leihgeraete / Restposten)
            jQuery('#left ul#main_navigation li.item4778 ul li.navi2').remove();
            jQuery('li.navi1 a[href="/shop/cat_id/produktprobe.4782"]').appendTo('#banner ul#meta_navigation li:last');

            jQuery('#left ul#main_navigation li.item4778 ul').children().prependTo('#banner ul#meta_navigation');
            jQuery('#left ul#main_navigation li.item4778').remove();

            var way='<li><a class="e1b navi1" href="/shop.php?wegbeschreibung=1" style="font-weight:bold;text-shadow:#c00001 1px 1px 1px;">Anfahrt</a></li>';
            jQuery(way).insertBefore('#meta_navigation li:first');

			
		//append facebook-like-button to Product Detail View
		  if (jQuery('div.produktBeschreibung')) {						  
			  jQuery('div.produktBeschreibung').append('<iframe src="http://www.facebook.com/plugins/like.php?href='+window.location.href+'&amp;layout=standard&amp;show_faces=false&amp;width=380&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=35" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:380px; height:35px;padding:10px 0 0 5px;" allowTransparency="true"></iframe>');			 
		  }

              // mod Testbericht Tab 
              if (jQuery('ul#Tab_Navi')) {
			jQuery('ul#Tab_Navi li a span span:contains("Testbericht")').parent().parent().parent('li').css({'float':'right','margin-right':'5px'});
              }


            // News-scrollable init
            jQuery(".scrollable").scrollable({
	keyboard: false,
	circular: true,
       vertical: false,
       items: '.items',
       next: '.next',
       prev: '.prev',
       speed: 500,
       onSeek: function(){ jQuery('span.counter span').html(this.getIndex() +1); }
});
            
        });

    })();

