/* ######################################################################################################
** ### ALLGEMEIN  ################################################################
** ######################################################################################################
*/

$("#search").ready(function() {
	$("#search #keywords").attr('autocomplete', 'off');																				
});


function popUp(url, b_scroll, breite, hoehe, name, status) {
	neues_fenster = open(url,name,'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars='+b_scroll+',resizable=yes,copyhistory=no,width='+breite+',height='+hoehe+'');
	neues_fenster.focus();
}

function clearInputfield(field) {
	if (field.name == "keywords") {
		if (field.value == 'Produktsuche')
		field.value = '';
		else if (field.value == '')
		field.value = 'Produktsuche';			
	} 
}

function hideIntelliSearch() {
	if (document.getElementById('intelliSearchResult')) {
		document.getElementById('intelliSearchResult').style.visibility = 'hidden';
	}
	return false;
}


/* ######################################################################################################
** ### ANGEBOTE QWICKS  ################################################################
** ######################################################################################################
*/

$('#top_content_home ul').ready(function() {
	if ($("#top_content_home ul").length > 0 ) {
		$('#top_content_home ul').kwicks({
			min : 55,  
			spacing : 0,
			sticky : true,
			defaultKwick : 0,
			event : 'mouseover'
		});
	}
});
				

/* ######################################################################################################
** ### QUICKNAVI  ################################################################
** ######################################################################################################
*/


function change_quicknav(url) {
	
	if (url.value != -1)
	location.href = url.value;
	return false;
} 


/* ######################################################################################################
** ### SHADOWBOX  ################################################################
** ######################################################################################################


if (typeof(Shadowbox) == "object") {
	Shadowbox.init({
		language: "de-DE",
		players: ["img","iframe", "html"],
		animate: false,
		animateFade: false,
		counterType: "skip",
		continuous: true
	});
}
*/

/* ######################################################################################################
** ### FANCYBOX  ################################################################
** ######################################################################################################
*/

$("#productInfoHeaderBox").ready(function() {
	
	$("#product-gallery").click(function() {
	
		var galleryItems = new Array();
		$("a[rel=product-gallery]").each(function(key, elm) {		
			galleryItems[key] = new Object();
			galleryItems[key]["href"] = $(this).attr('href');
			galleryItems[key]["title"] = $(this).attr('title');		
		});
		
		$.fancybox(galleryItems, {
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'titlePosition' 	: 'over',
			'overlayOpacity'	: 0.4,
			'type' : 'image',
			'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
				return '<span id="fancybox-title-over">' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
			}
		 });
		
		return false;
	});
});

$("div.productsOptions").ready(function() {
	
	// link einblenden sofern benoetigt
	if ($("#attribImages_optionsList img").length > 0) {
		$("a.desc-gallery-sp").show();
	}
	
	$(".desc-gallery-sp").click(function() {
	
		var descItems = new Array();
		$("#attribImages_optionsList img").each(function(key, elm) {		
			descItems[key] = new Object();
			descItems[key]["href"] = "http://www.gazina.de"+$(this).attr('src').replace('_a.','_l.');
			descItems[key]["title"] = $(this).attr('alt');
		});
		
		$.fancybox(descItems, {
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'titlePosition' 	: 'over',
			'overlayOpacity'	: 0.4,
			'type' : 'image',
			'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
				return '<span id="fancybox-title-over">' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
			}
		 });
		
		return false;
	});
});


$("div.productsOptions").ready(function() {
	
	// link einblenden sofern benoetigt
	$(".attribImages_unSpecialList").each(function(key, elm) {
		var listId = $(this).attr('id').replace("attribImages_", "");
		if ($("#attribImages_"+listId+" img").length > 0) {
			$("a#desc-gallery_"+listId).show();
			return false;
		}
	});
	
	$(".desc-gallery").click(function() {
	
		var descItems = new Array();
		$(".attribImages_unSpecialList img").each(function(key, elm) {		
			descItems[key] = new Object();
			descItems[key]["href"] = "http:///www.gazina.de"+$(this).attr('src').replace('_a.','_l.');
			descItems[key]["title"] = "Material: "+$(this).attr('alt');		
		});
	
		$.fancybox(descItems, {
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'titlePosition' 	: 'over',
			'overlayOpacity'	: 0.4,
			'type' : 'image',
			'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
				return '<span id="fancybox-title-over">' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
			}
		 });
		
		return false;
	});
});


$("#productInfoHeaderBox").ready(function() {									
	$("a[rel=product-gallery]").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'overlayOpacity'	: 0.4,
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-over">' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
		}
	});
});

$("#giftCartBox").ready(function() {
	$("#giftCartLink").fancybox({
			'width'				: 600,
			'height'			: 400,
			'autoScale'			: true,
			'titlePosition'			: 'none',
			'transitionIn'			: 'none',
			'transitionOut'			: 'none',
			'hideOnContentClick'	: false
	});
});

$(".formPopupLink").ready(function() {
	$(".formPopupLink").fancybox({
		'width'				: 690,
		'height'			: '90%',
		'autoScale'			: true,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'hideOnContentClick'	: false,
		'type'				: 'iframe',
		'titleShow' 	: false,
		'centerOnScroll' : true	
	});		
});

$(".contentPopupLink").ready(function() {
	$(".contentPopupLink").fancybox({
		'width'				: 690,
		'height'			: '90%',
		'autoScale'			: true,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'hideOnContentClick'	: false,
		'type'				: 'iframe',
		'titleShow' 	: false
	});		
});

$(".contentPopupLinkShort").ready(function() {
	$(".contentPopupLinkShort").fancybox({
		'width'				: 690,
		'height'			: 500,
		'scrolling'		: 'no',
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'hideOnContentClick'	: false,
		'type'				: 'iframe',
		'titleShow' 	: false
	});		
});

$(".contentPopupLinkShortSc").ready(function() {
	$(".contentPopupLinkShortSc").fancybox({
		'width'				: 690,
		'height'			: 600,
		'scrolling'		: 'auto',
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'hideOnContentClick'	: false,
		'type'				: 'iframe',
		'titleShow' 	: false
	});		
});



/* ######################################################################################################
** ### HERSTELLER CAROUSEL HOME  ################################################################
** ######################################################################################################


$("#manufacturersCarousel").ready(function() {
	if ($("#manufacturersCarousel li").length > 0) {
		$('#manufacturersCarousel').jcarousel({
			scroll:3,
			visible:4
		});
	}
});

*/
/* ######################################################################################################
** ### THUMBNAIL PRODUCTINFO + XSELL  ################################################################
** ######################################################################################################


$("#productImgThumbsCarousel").ready(function() {
	$('#productImgThumbsCarousel').jcarousel({
		vertical:true,
		scroll:4,
		visible:4
	});
});


$("#productXsellCarousel1").ready(function() {
		$(".jcarousel-skin-productxsell").each(function() {
		var carouselId = $(this).attr('id');
		$("#"+carouselId).ready(function() {
			$("#"+carouselId).jcarousel({
				scroll:3,
				visible:3
			});
		});		
	});	
});	

*/
/* ######################################################################################################
** ### GLOSSAR in Tickbox oeffnen - Pfad auf PopUp aendern (wg. SEO) ####################################
** ######################################################################################################
*/

$("ul.glossary_items").ready(function() {
	if ($("ul.glossary_items li").length > 0) {
		$("ul.glossary_items li a.entries_name").each(function() {		
			var popup_href = $(this).attr('href').replace('glossary_entry.php','glossary_entry_popup.php');
			$(this).attr('href', popup_href);
			$(this).attr('rel', 'shadowbox;height=600;width=620');	
		});
	}	
});


/* ######################################################################################################
** ### ACCORDION ####################################
** ######################################################################################################
*/

$(document).ready(function(){
	$("#accordion").accordion({											
		header: "h6",
		autoHeight: false 
	});
});


/* ######################################################################################################
** ### CART-POPUP  ################################################################
** ######################################################################################################
*/

$("div#boxCart").ready(function(){
	$("div#boxCart").mouseover(function(){
		$("div#boxCartFull").show();
	}).mouseout(function(){
		$("div#boxCartFull").hide();
	});
});


/* ######################################################################################################
** ### PRODUCT-INFO TABS  ################################################################
** ######################################################################################################
*/

$("div#tabs").ready( function() {
  var tabContainers = $('div#tabs > div > div');
    
	$('div#tabs ul.tabNavigation a').click(function (obj) {
			tabContainers.hide().filter(this.hash).show();
			
			$('div#tabs ul.tabNavigation li img').each(function(key, elm) { 
				elm.src = elm.src.replace( '_over.gif', '.gif');
			});
			
			$('div#tabs ul.tabNavigation a').removeClass('selected');
			
			var src = $(this).find('img').attr("src").replace('.gif','_over.gif');
			$(this).find('img').attr("src", src);
			
			$(this).addClass('selected');

			return false;
	}).filter(':first').click();
	
	
	$('div#tabs ul.tabNavigation a').mouseover(function (obj) {
			
			if ($(this).hasClass("selected"))
			return false;
			
			var src = $(this).find('img').attr("src").replace('.gif','_over.gif');
			$(this).find('img').attr("src", src);
			return false;
	});
	
	$('div#tabs ul.tabNavigation a').mouseout(function (obj) {
			
			if ($(this).hasClass("selected"))
			return false;
			
			var src = $(this).find('img').attr("src").replace('_over.gif','.gif');
			$(this).find('img').attr("src", src);		
			return false;
	});

});


/* ######################################################################################################
** ### PRODUCT-INFO REVIEWS  ################################################################
** ######################################################################################################
*/

$("div#box_ReviewWrite").ready( function() {
	$("div#box_ReviewWrite").hide();
});

function write_review(form) {
	$val_pid = $("#review_pid").val();
	$val_rating = $('input:radio[name=review_rating]:checked').val();
	$val_author = $("#review_author").val();
	$val_author_town = $("#review_author_town").val();
	$val_comment = $("#review_comment").val();
	
	$("#box_ReviewWrite").html('<p class="error" style="text-align:center;">bitte warten...</p>'); 
	bodyContent = $.ajax({
			url: "/product_reviews_write_ajax.php?action=process&products_id="+$val_pid,
			global: false,
			type: "POST",
			data: "rating="+$val_rating+"&author="+$val_author+"&author_town="+$val_author_town+"&comment="+$val_comment,
			success: function(ret_msg){
				$("#box_ReviewWrite").html('<p class="error">'+ret_msg+'</p>'); 
			}
	 }).responseText;
	return false;
}

function showDetail(element) {
	if (document.getElementById(element)) {
		if (document.getElementById(element).style.display == "none") {
			document.getElementById(element).style.display = "";
		} else {
			document.getElementById(element).style.display = "none";
		}
	}
}


/* ######################################################################################################
** ### AGB CHECKOUT CONFIRMATION  ################################################################
** ######################################################################################################
*/

function check_conditions() {
	if ($('#conditions').length > 0 ) {
		if ($('#conditions').attr('checked')) { 
			return true;
		} else {
			alert("Bitte bestätigen Sie die Allgemeinen Geschäftsbedingungen gelesen zu haben.");
			return false;
		}
	} else {
		return true;	
	}
}


/* ######################################################################################################
** ### ROLLOVER  ################################################################
** ######################################################################################################
*/

$(document).ready( function()
{
	 KM.rollover.init();
});

KM = {};

KM.rollover =
{
	 init: function()
	 {
			this.preload();
		 
			$(".ro").hover(
				 function () { $(this).attr( 'src', KM.rollover.newimage($(this).attr('src')) ); },
				 function () { $(this).attr( 'src', KM.rollover.oldimage($(this).attr('src')) ); }
			);
	 },

	 preload: function()
	 {
			$(window).bind('load', function() {
				 $('.ro').each( function( key, elm ) { $('<img>').attr( 'src', KM.rollover.newimage( $(this).attr('src') ) ); });
			});
	 },
	 
	 newimage: function( src )
	 {
			return src.substring( 0, src.search(/(\.[a-z]+)$/) ) + '_over' + src.match(/(\.[a-z]+)$/)[0];
	 },

	 oldimage: function( src )
	 {
			return src.replace(/_over\./, '.');
	 }
};
