$().ready(function(){
		$("#categories_container").accordion({
			header:'.title',
			active:false,
			alwaysOpen:true,
			autoheight:false
		});
		do_ajax_init();
		do_login_click();
		do_max_dd_init();
		do_check_highlight();
		do_ship_link();
		setupAutocomplete();
				   });


var bildArray=new Array(1,2,3,4,5,6,7,8,9,10);
function bild(nummer){
				
	if(document.getElementById)
	for (a=0;a<bildArray.length;a++){
		if(bildArray[a]!=nummer){
			$("#bild"+bildArray[a]).hide();
			
		}else{
			$("#bild"+nummer).show();
			
		}
	}
	return false;
}

   function check_ssl(mod_url){
 					// SSL mod
					if(typeof mod_url != 'undefined'){
					var mod_href = '';
					if(typeof mod_ajax_request != 'undefined'){
					var mod_href = mod_url.replace(mod_ajax_normal_server,mod_ajax_ssl_server)
					}else{
							if(mod_url.search('https:') != -1){
							var mod_href = mod_url.replace('https:','http:')
							}else{
							var mod_href = mod_url;
							}
					}
					return mod_href;
					}
 }
 
 
   function getNewFilters(welcher){
 var checked_basename = check_ssl($('#use_filters').attr('action'));
	var options = { 
		url:checked_basename,
        target:        '#special_change',
		beforeSubmit:  function(){$('#special_change').block({overlayCSS:  {backgroundColor: '#000',opacity:0.2},message:'<img src="images/loading.gif" alt="loading..." title="loading..." />',css:{width:'56px',border:'1px solid #aaa'} }); },
		data: {ajax:'ajax_calls',what:'getNewFilters'},  
        success:       function() {doAjaxSubmit();}  
		
		}
		$('#use_filters').ajaxSubmit(options); 
		return false;
}
  function doAjaxSubmit(){
	  var checked_basename = check_ssl($('#use_filters').attr('action'));
		var options = {
			url:checked_basename,
			target: '#putin_main',
			data:{ajax:'1'},
        	beforeSubmit:  function(){$('#putin_main').block({overlayCSS:  {backgroundColor: '#000',opacity:0.2},message:'<img src="images/loading.gif" alt="loading..." title="loading..." />',css:{width:'56px',border:'1px solid #aaa'} });},  // pre-submit callback 
        	success:       function(data){do_max_dd_init();$('#putin_main').unblock();}   // post-submit callback 
    	};
	  $.ajax({url:checked_basename,data:{ajax:'1'},dataType:'html',success:function(data){$("html").animate({ scrollTop: 200 }, 100);$('#putin_main').html(data);do_max_dd_init();},beforeSend:function(){$('#JT').hide(200);if($('#countdown_product_1').length){$('#countdown_product_1').countdown('destroy');}$('#putin_main').block({overlayCSS:  {backgroundColor: '#000',opacity:0.2},message:'<img src="images/loading.gif" alt="loading..." title="loading..." />',css:{width:'56px',border:'1px solid #aaa'} }); }});
	  
	  }


function do_ajax_init(){

										$('.subnav_ajax').bind('click',function(){
								var checked_basename = check_ssl($(this).attr('href'));
								
								$.ajax({url:checked_basename,data:{ajax:'1'},dataType:'html',success:function(data){$("html").animate({ scrollTop: 200 }, 100);$('#putin_main').html(data);},beforeSend:function(){$('#JT').hide(200);if($('#countdown_product_1').length){$('#countdown_product_1').countdown('destroy');}$('#box_whats_new').remove();$('#putin_main').html('<div class="ajax_loading"><img src="images/loading.gif" alt="loading..." title="loading..." /></div>');}});
												});
	
}

//Bonus start
var submitter = null;
function submitFunction() {
   submitter = 1;
   }
//Bonus ende

function do_login_click(){
					$('#login_show').click(function(){
								if($('#box_login').is(':hidden')){
								$('#login_show').append('<span class="close_login">X</span>');	
								}else{
								$('#login_show > span.close_login').remove();	
								}
							$('#box_login:visible').slideUp(500);
							$('#box_login:hidden').slideDown(500);
							return false;
											   });	
}

function do_manu_scroll(){
		    $(".manufacturers_scroll").jMyCarousel({
		        visible: '100%',auto:true,speed:1500});	
}

function do_max_dd_init(){
	
	function return_options(action_url){
		var checked_basename = check_ssl(action_url);
		var options = {
			url:checked_basename,
			target: '#putin_main',
			data:{ajax:'1'},
        	beforeSubmit:  function(){$('#putin_main').block({overlayCSS:  {backgroundColor: '#000',opacity:0.2},message:'<img src="images/loading.gif" alt="loading..." title="loading..." />',css:{width:'56px',border:'1px solid #aaa'} }); },  // pre-submit callback 
        	success:       function(data){do_max_dd_init();$('#putin_main').unblock();}   // post-submit callback 
    	};
		return options;
	}
	
	$('.max_result_dd').each(function(){
									  $(this).ajaxForm(return_options($(this).attr('action')));
			$(this).children('select[name=max_result],select[name=multisort]').bind('change',function(){ $(this).parent('.max_result_dd').ajaxSubmit(return_options($(this).parent('.max_result_dd').attr('action')));return false;});
									  });	
}

 function do_check_highlight(){
//var checked_basename = check_ssl(window.location.href);
//$.ajax({url:checked_basename,data:{ajax:'ajax_calls',what:'highlight'},type:'POST',dataType:'json',success:function(data){highlight_it(data)},beforeSend:function(){}});	
highlight_it();
 }
 
 function highlight_it(data){
	 var config = {    
     sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
     interval: 300, // number = milliseconds for onmouseover polling interval    
     over: function(){JT_show($(this));}, // function = onmouseover callback (REQUIRED)    
     timeout: 500, // number = milliseconds delay before onmouseout    
     out: function(){} // function = onmouseout callback (REQUIRED)    
	};
	$(".highlight").hoverIntent(config);
	  $(".highlight").live('click',function(){
												JT_show($(this));
												return false;
												});
	  /*if(typeof(data.highlight)!='undefined'){
	 $.each(data.highlight, function(json_id,json_data){
  $('body').highlight(json_data.title,json_data.mod_id);
									 });
	  }*/
 }
 
   function do_ship_link(){
		$(".ship_link").live('click',function(){								   
window.open($(this).attr('href'),'popup','toolbar=0, scrollbars=yes, resizable=yes, height=720, width=743');
return false;});
	
 }
 
  function setupAutocomplete(){
	$(".search_input").autocomplete(check_ssl($('#quick_find').attr('action')),{width:300,minChars:2,scrollHeight: 225,max:99,formatResult: function(row) {
			row = row.join();
			row = row.replace(/<(.*?)>/,"");
			row = row.replace(/<(.*?)>/,"");
			return row.replace(/<\/(.*?)>/,"");
		},selectFirst:false,delay:400,matchContains:true
		,extraParams:{'ajax':'1','autocomplete':'yes'}
		
		});
 	
 }
