/*
$(document).ready(function(){
    $("ul.sf-menu li.no ul").each().superfish({ 
        //animation: {height:'show'},   // slide-down effect without fade-in 
        delay:     500               // halt a second delay on mouseout 
    }); 
}); 
*/

/*
$(document).ready(function(){
        $("ul.sf-menu li.no ul").each()
        .superfish({
                animation : { opacity:"show", height:"show" }
        })
        .find(">li:has(ul)")
                .mouseover(function(){
                        $("ul", this).bgIframe({opacity:false});
                })
                .find("a")
                        .focus(function(){
                                $("ul", $(".nav>li:has(ul)")).bgIframe({opacity:false});
                        });
});
*/

// This file demonstrates the different options of the pagination plugin
// It also demonstrates how to use a JavaScript data structure to 
// generate the paginated content and how to display more than one 
// item per page with items_per_page.
        
/**
 * Callback function that displays the content.
 *
 * Gets called every time the user clicks on a pagination link.
 *
 * @param {int}page_index New Page index
 * @param {jQuery} jq the container with the pagination links as a jQuery object
 */


function pageselectCallback(page_index, jq){
        // Get number of elements per pagionation page from form
        var items_per_page = $('#items_per_page').val();
        var max_elem = Math.min((page_index+1) * items_per_page, members.length);
        var newcontent = '';
        
        // Iterate through a selection of the content and build an HTML string
        for(var i=page_index*items_per_page;i<max_elem;i++) {
            newcontent += '<li>' + members[i][0]; + '</li>';
        }
        
        // Replace old content with new content
        $('#Searchresult').html(newcontent);
        
        // Prevent click eventpropagation
        return false;
    }
    
    // The form contains fields for many pagiantion optiosn so you can 
    // quickly see the resuluts of the different options.
    // This function creates an option object for the pagination function.
    // This will be be unnecessary in your application where you just set
    // the options once.
    function getOptionsFromForm(){
        var opt = {callback: pageselectCallback};
        // Collect options from the text fields - the fields are named like their option counterparts
        $("input:text").each(function(){
            opt[this.name] = this.className.match(/numeric/) ? parseInt(this.value) : this.value;
        });
        // Avoid html injections in this demo
        var htmlspecialchars ={ "&":"&amp;", "<":"&lt;", ">":"&gt;", '"':"&quot;"}
        $.each(htmlspecialchars, function(k,v){
            opt.prev_text = opt.prev_text.replace(k,v);
            opt.next_text = opt.next_text.replace(k,v);
        })
        return opt;
    }
    
// When document has loaded, initialize pagination and form 
$(document).ready(function(){

    $('#gmainmenu ul').superfish({ 
        delay: 200, animation: {opacity:'show'}, speed: 350, autoArrows: false, dropShadows: false
    });
    //.find('li.no ul').bgIframe({opacity:false});

    /*    
    // Generate an Array of Data from the Contents of the List
    members = new Array();
    eintrag = new Array(3);
    
    $("ul#Searchresult li").each(function() { 
      
      eintrag=[ $(this).html() ];
      members.push( eintrag ); 
    });
    
    $('#Searchresult').html('<li>Test! Die Liste enthaelt ' + members.length + ' Elemente</li>');
    
    
    // Seitenbrowser erzeugen
    $("#Pagination").pagination(members.length, getOptionsFromForm());
        
    $("#setoptions").click(function(){
      // Re-create pagination content with new parameters
      $("#Pagination").pagination(members.length, getOptionsFromForm());
    }); 
    
    */
    
    //$('#gmainmenu li.no ul').bgiframe();
    //$('h4.topping').bgiframe();
    
    $(".perpage a").click(function(){
      // Re-create pagination content with new parameters
      opt = Array();
      console.log( $(this).attr('id').replace('perpage-', '') );
      //$("#Pagination").pagination(members.length, opt);
      
      // Alle zusammengeh?rigen Buttons deaktivieren
      $(".perpage a").each(function(){
      	$(this).removeClass("current");
      });
      
      // GedrÙckten Button aktivieren
      $(this).addClass("current");
      
      
      
      
      //members.sort(function(a,b) { return parseFloat(a.test) - parseFloat(b.test) } );
      
      //members.drawLinks();
      
    }); 


/*


    // Produktdetails ein- oder ausblenden
    $(".showdet a").click(function(){
      
      // Alle zusammengeh?rigen Buttons deaktivieren
      $(".showdet a").each(function(){
      	$(this).removeClass("current");
      });
      
      // GedrÙckten Button aktivieren
      $(this).addClass("current");
      if ( $(this).is('.on') ) {
          $("li img").each(function(){ $(this).show(); });
      } else {
          $("li img").each(function(){ $(this).hide(); });
      }
    }); 
    
    
    
    // Produktvarianten ein- oder ausblenden
    $(".showvar a").click(function(){
      
      // Alle zusammengeh?rigen Buttons deaktivieren
      $(".showvar a").each(function(){
      	$(this).removeClass("current");
      });
      
      // GedrÙckten Button aktivieren
      $(this).addClass("current");
      if ( $(this).is('.on') ) {
          $("p.var").each(function(){ $(this).show(); });
      } else {
          $("p.var").each(function(){ $(this).hide(); });
      }
    }); 
	
	*/
	
	
	
	function date_de(s) {
		var a = s.split('.');
		a[1] = a[1].replace(/^[0]+/g,"");
		return new Date(a.reverse().join("/")).getTime();
	}
	
	
	// Check aviability of the Product and breakdown the response and parse the result into the page 
	/*
	$("#sidebar input").change(function(){
		
		var start = date_de( $("#checkav-start-date").val() );
		var end = date_de( $("#checkav-end-date").val() );
		if ( start <= end ) {
			$("#checkav-result").text("Bitte wartenÉ").removeClass("nichtverfuegbar").removeClass("verfuegbar").removeClass("load");
			$.get('/index.php?id=25&dgact=produkt_detail&artikelnummer=308010000&position=1', {}, function(html) {
				html = $(html).find('#checkav-result').html();
				console.log(html);
				if( html.search( "Produktmenge verf" ) ) {
					$( "#checkav-result" ).text( "Der Artikel ist in diesem Zeitraum nicht ausreichend verfŸgbar." ).removeClass( "load" ).addClass( "nichtverfuegbar" );
					//$("#checkav-result").text().removeClass("load").addClass("nichtverfuegbar");
				} else {
					$("#checkav-result").text("Der Artikel ist verfŸgbar.").removeClass("load").addClass("verfuegbar");
					//$("#checkav-result").text("Der Artikel ist verfŸgbar.").removeClass("load").addClass("verfuegbar");
				}
			});
		} else {
			$("#checkav-result").text("Bitte den gewŸnschten Zeitraum angeben.").removeClass("load").addClass("nichtverfuegbar");
		}
	});
	*/
	
});





