// JavaScript Document

$(document).ready(function() {

	if($(".content_slides").length>0) {
		$('.content_slides').cycle({
			fx: 'fade'
		});
	}
	
	if($("#tabs").length>0) { $( "#tabs" ).tabs(); }

	$(".ceebox").ceebox({
		titles: false,
		htmlWidth: 889,
		htmlHeight: 600,
		vidWidth:889,
		vidHeight:600,
		onload: function() {  if($("#tabs").length>0) { $( "#tabs" ).tabs("destroy"); } }, 
		unload: function() {  if($("#tabs").length>0) { $( "#tabs" ).tabs(); } }
	});
	
	$(".ceeboxAudio").ceebox({
		titles: false,
		htmlWidth: 350,
		htmlHeight: 260,
		onload: function() {  if($("#tabs").length>0) { $( "#tabs" ).tabs("destroy"); } }, 
		unload: function() {  if($("#tabs").length>0) { $( "#tabs" ).tabs(); } }
	});
	
	$(".ceeboxKaufen").ceebox({
		titles: false,
		htmlWidth: 650,
		htmlHeight: 580,
		onload: function() {  if($("#tabs").length>0) { $( "#tabs" ).tabs("destroy"); } }, 
		unload: function() {  if($("#tabs").length>0) { $( "#tabs" ).tabs(); } }
	});
	
	$(".ceeboxKaufenIphone").ceebox({
		titles: false,
		htmlWidth: 650,
		htmlHeight: 840,
		onload: function() {  if($("#tabs").length>0) { $( "#tabs" ).tabs("destroy"); } }, 
		unload: function() {  if($("#tabs").length>0) { $( "#tabs" ).tabs(); } }
	});
	
	if($("a.lupe").length>0) {
		$("a.lupe").fancybox({
			'transitionIn': 'elastic',
			'overlayColor': '#000000',
			'transitionOut': 'elastic'
		});
	}
	
	$("a.fb_single").fancybox({
			'transitionIn': 'elastic',
			'overlayColor': '#000000',
			'transitionOut': 'elastic'
		});
	
	
	var pic_r = 3+($("a.pic").length*19)-19;
	$("a.pic").each(function(index) {
		$(this).css({ right: pic_r });
		pic_r -= 19;
		$(this).click(function() {
			change_product_pic(index,this);
			$(this).parent().children("a.pic").each(function() {
				$(this).removeClass("active");
			});
			$(this).addClass("active");
		});
	});
	
	/*$(".product_content_optional DIV.optional").each(function() {
		$(this).css({ display: "none", overflow: "hidden"  });														  
	});
	*/
	
	$(".product_content_optional a[rel=subsection]").each(function(index) {
		$(this).click(function() {
			open_optional_content(index);					   
		});
	});
	
	
	$("p").each(function() {
		$(this).addClass("hyphenate").addClass("text").attr("lang", "de");					 
	});
	
	Hyphenator.config({
		displaytogglebox : false,
		minwordlength : 4
	});
	Hyphenator.run();
	
	/*$( ".product_content_optional" ).accordion({
		autoHeight: false,
		navigation: true,
		collapsible: true,
		active: false
	});
	*/
	
	
	
	$('a[rel="subsection"]').CreateBubblePopup({
										position: 'top',
										align: 'center',
										width: 300,
										innerHtml: '<img src="/js/jquerybubblepopup-theme/loading.gif" style="border:0px; vertical-align:middle; margin-right:10px; display:inline;" />Inhalt wird geladen!',
										innerHtmlStyle: { color:'#FFFFFF', 'text-align':'left' },
										themeName: 'all-black',
										themePath: '/js/jquerybubblepopup-theme'
								  	  });

		// add a mouseover event for the "button" element...
		$('a[rel="subsection"]').mouseover(function(){

				//get a reference object for "this" target element
				var button = $(this);
	
				//load data asynchronously when mouse is over...
				$.get("/scripts/getAjax.php?site="+$(this).attr("href"), function(data) {
	
					//////////////////////////////////////////////////////////
					// IN THIS EXAMPLE,
					// the .get() method loads the data immediately, 
					// then we force the script to pause for 2 seconds, 
					// to see the loading effect; this is only an example,
					// feel free to delete this code in a real application...
					//
					var seconds_to_wait = 2;
					function pause(){
						var timer = setTimeout(function(){
							seconds_to_wait--;
							if(seconds_to_wait > 0){
								pause();
							}else{
	
								//set new innerHtml for the Bubble Popup
								button.SetBubblePopupInnerHtml(data, false); //false -> it shows new innerHtml but doesn't save it, then the script is forced to load everytime the innerHtml... 
								
								// take a look in documentation for SetBubblePopupInnerHtml() method
	
							};
						},1000);
					};pause();
					//////////////////////////////////////////////////////////
	
				}); 

		}); //end mouseover event
	
	

});

function change_product_pic(id,obj) {
	$(obj).parent().children("IMG").each(function(index) {
		if(index==id) {
			$(this).removeClass("dis");
		} else {
			$(this).addClass("dis");
		}
	});
	
	$(obj).parent().children("a.lupe").each(function(index) {
		if(index==id) {
			$(this).removeClass("dis");
		} else {
			$(this).addClass("dis");
		}
	});
	
}

function open_optional_content(id) {
	$(".product_content_optional DIV.optional").each(function(index) {	
		if(index==id) {
			var h = $(this).height();
			$(this).css({ height: 0, display: "block", opactiy: 0 });
			$(this).animate({ height: h, opacity: 1 }, 1000);
		}
	});
}

