function addBookmark(title,url) {
	if (window.sidebar) { 
	window.sidebar.addPanel(title, url,"http://www.nails-beauty24.com"); 
	} else if( document.all ) {
	window.external.AddFavorite( url, title);
	} else if( window.opera && window.print ) {
	return true;
	}
}


$(document).ready(function() {
						   
				   
	// Init Dialog	
	var dl = $('#dialog').dialog({ autoOpen: false, width: 450, height:150, modal: true});					   


	$('select').selectbox();
	$('.go_article').change(function(){ 
		 GoArticle($(this).val());
	 });



	// Init Form 
	$("div.varianten:has(input)").each(function() {
		
		// height update
		h = Math.ceil($(this).height() / 2);
		d = $("div.pic", $(this).parents("form"));
		t = $("div.title", $(this).parents("form"));
		d.height(d.height()-h + "px");
		t.height(t.height()-h + "px");
		
		cv = $("input[type='hidden']",this).val();
		$("a.vr_selector",this).filter('[val="'+cv+'"]').attr("sel", true);
		

		$("a.vr_selector", this).click(function(){
												
			if($(this).attr("href")!="#") return true;									

			$("a.vr_selector", $(this).parents("form")).attr("sel", "false");
			
			i = $('input[name="'+$(this).attr("tar")+'"]', $(this).parents("form")); 	  
			i.val($(this).attr("val"));
			$(this).attr("sel", true);
			
			return false;
			
	 	});
									 
	});
	
	

	
	// Init Submit
	
	$('form input[name=artikelid]').each(function() {	
		$(this).parents("form").submit(function(){	
			
			OpenDialog("Warenkorb", 400, 130, {});
											
		    $.post(system_path+"api.php", "cmd=bs_add_article&"+$(this).serialize(), 
				function (data) { 
				
					dl.html(data);
					if(el = $("#dialog div[add_bs]")) {
						if(el.attr("add_bs")=="true") {
							dl.dialog( "option", "buttons", {
							  "Weiter einkaufen": function() { $(this).dialog("close"); },
							  "zum Warenkorb": function() {  $(document).attr("location", system_path+"themes/warenkorb/index.php"); }
							});
						
						} else if(el.attr("add_bs")=="false") {
							dl.dialog( "option", "buttons", {
							  "Fenster Schließen": function() { $(this).dialog("close"); }
							});
						}
					}
				
					
					$.post(system_path+"api.php", "cmd=update_bs", function(data) { $('#NB_Basket').html(data) }, "html");
					
					$('div#NB_Basket').load("api.php?cmd=update_bs");
					
					//UpdateDialogHeight();

				}, "html");
		 

			return false;
		});
		
		
	 });
	

	$("div[zoom]").click(function(){
							//	alert($(this).attr("zoom"));  
								
		OpenDialog("Zoom", 450, 450, {});
		
		dl.html('<div class=pic_viewer><div class=img></div></div>')
		$(".pic_viewer div.img", dl).css({"background-image":"url("+$(this).attr("zoom")+")"});
								  
	});
	
	
	
	// Focus bugfix
	
	 if((/MSIE ((5\.5)|6|7)/.test(navigator.userAgent) && navigator.platform == "Win32")) {
		 
	     $('input').focus(function(){ $(this).addClass("infocus"); });
	     $('input').focusout(function(){ $(this).removeClass("infocus");});
	
		 $('textarea').focus(function(){ $(this).addClass("txfocus"); });
		 $('textarea').focusout(function(){ $(this).removeClass("txfocus"); });
	
	 }

    
	  if ((/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32")) {

		 // Bestseller
		 $('.bestseller.item').hover(function(){ $(this).addClass("bst_slr_hover");  }, function(){ $(this).removeClass("bst_slr_hover"); });
		
		  // Fix Button Hover
		 $('.bu1').hover(function(){ $(this).addClass("hover_bu1");  }, function(){ $(this).removeClass("hover_bu1"); });
		 $('.bu2').hover(function(){ $(this).addClass("hover_bu2");  }, function(){ $(this).removeClass("hover_bu2"); });
		 $('.bu3').hover(function(){ $(this).addClass("hover_bu3");  }, function(){ $(this).removeClass("hover_bu3"); });
		 $('.bu4').hover(function(){ $(this).addClass("hover_bu4");  }, function(){ $(this).removeClass("hover_bu4"); });
		 
		 // Button width 
		 $('.button').each(function() { $(this).css({"width":($("span", this).width() + 25) + "px" }); }); 
		 
		 // Min Product 
		 $('.product.start .item').hover(function(){ $(this).addClass("hover"); }, function(){ $(this).removeClass("hover"); }) 

		 // Product 
		 $('.product .item').hover(function(){ $(this).addClass("pover"); }, function(){ $(this).removeClass("pover"); }) 
		 
		
		 // get all pngs on page
		 $('img[src$=.png]').each(function() {
		   if (!this.complete) {
			 this.onload = function() { fixPng(this) };
		   } else {
			 fixPng(this);
		   }
		 });
	  }

 
	 function fixPng(png) {
	   // get src
	   var src = png.src;
	   // set width and height
	   if (!png.style.width) { png.style.width = $(png).width(); }
	   if (!png.style.height) { png.style.height = $(png).height(); }
	   // replace by blank image
	   png.onload = function() { };
	   png.src = blank.src;
	   // set filter (display original image)
	   png.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
	 }



});




function GoArticle(id) {
	$(document).attr("location", system_path+"artikel_"+id+"_.html");	 
}


function OpenDialog(titel, width, height, buttons) {
		
		
		dl = $('#dialog');
		dl.html('');
		dl.dialog( "option", "title", titel );
		dl.dialog( "option", "width", width );
		dl.dialog( "option", "height", height );
		dl.dialog( "option", "buttons", buttons);
		dl.dialog('open');
}
	
function UpdateDialogHeight() {
	
	h = $('#dialog div:first').innerHeight()+85;	
	$('#dialog').dialog( "option", "height", h);
}




	