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

if (window.name == "") {
	window.name = "mainWindow";
}
	
self.focus();


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';			
	} 
	if (field.name == "email") {
		if (field.value == 'Ihre E-Mail-Adresse')
		field.value = '';
		else if (field.value == '')
		field.value = 'Ihre E-Mail-Adresse';			
	} 
}


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


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

// Klick auf Layergrafik
$("#col3_content").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;
	});
});

// Thumbnails
$("#productImgThumbs").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>';
		}
	});
});

$(".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'			: 550,
		'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
	});		
});

/* ######################################################################################################
** ### 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;	
	}
}


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

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

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


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

$("div#tabsB").ready( function() {
  var tabContainers = $('div#tabsB > div > div');
    
	$('div#tabsB ul.tabNavigation a').click(function (obj) {
			tabContainers.hide().filter(this.hash).show();
		 // alert(this.name);
			$('div#tabsB ul.tabNavigation a').removeClass('selected');
			$(this).addClass('selected');
			
			$('div#tabsB ul.tabNavigation a span').removeClass('selected');
			$(this).find('span:first-child').addClass('selected');
		
			return false;
	}).filter(':first').click();
});

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


/* ######################################################################################################
** ### 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";
		}
	}
}

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


/* ######################################################################################################
** ### ROLLOVER PRODUCT UND CONTENT NAVI (TOP)  ################################################################
** ######################################################################################################
*/

$(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\./, '.');
	 }
};
