/**
 * Uhlsport productdetails.js
 * XML Generator für Flash
 * -------------------------------------------------------------------------
 * @author Weitclick
 * @copyright Copyright(C) 2009, Weitcklick
 * @version $Id: import.php 1 2009-01-21 15:28:03Z ma $
 * @revision $LastChangedRevision:0 $
 **/

var strZoomImgSize = '350x350';
var mediaPath = '/fileadmin/templates/media/products/';

function InitSub() {
	if ($.browser.name == "msie") {
		$('#product-detail_accordion').accordion({ 
		    active: false, 
		    header: 'h3',
		    autoHeight: true,
		    fillSpace: false,
			alwaysOpen: false   
		});
	} else {	
		$('#product-detail_accordion').accordion({ 
		    active: false, 
		    header: 'h3',
		    autoHeight: false,
		    fillSpace: false,
			alwaysOpen: false   
		});
	}
	
	$('a').tooltip({ 
	    track: true, 
	    delay: 0, 
	    showURL: false, 
	    showBody: " - ", 
	    fade: 250 
	});
	
	
	//Zentrieren der Details
	var windowWidth 	= $(window).width();
	var detailsWidth	= 440+440+10;
	
	$('div#previous-product').width(((windowWidth - detailsWidth)/2)-10);
	$('div#next-product').width(((windowWidth - detailsWidth)/2)-10);
	
	if (window.console && window.console.log)
		window.console.log('[zentrierenDetails] ' + windowWidth + ' zu ' + detailsWidth + ' max: '+(windowWidth - detailsWidth)/2);

}

function switchProductImg(imgItem) {
	var strImgPath = mediaPath+'350x350/'+imgItem;
	
	$('#product-detail_bigimage').attr('src',strImgPath);
	$('img[title="zoomimage"]').attr('src',strImgPath);
	
	$('#product-detail_bigimage').ifixpng();
}

function switchProductImgZoom(imgItem)
{
	var strImgPath = mediaPath+strZoomImgSize+'/'+imgItem;
	$('img[title="zoomimage"]').attr('src',strImgPath);
	$('img[title="zoomimage"]').ifixpng();
}	

function zoomImage() {
	var windowHeight 	= $(window).height();
	
	if (windowHeight > 800) {
		strZoomImgSize = '600x600';
	} else if (windowHeight > 500) {
		strZoomImgSize = '450x450';
	}
	
	var imgItem 		= $('#product-detail_zoomimage').attr('src');
	var strImgPath		= imgItem.replace(/350x350/,strZoomImgSize);
	$('#product-detail_zoomimage').attr('src',strImgPath);

	var strContent 		= $('#ZoomImageBox').html();
		
	$.floatbox({
        content: strContent,
        fade: true
    });
    
    $('img[title="zoomimage"]').ifixpng(); 
}

var last_recipient_name = '%recipient_name%';
var last_sender_name = '%sender_name%';

function tellAfriend_go_step2() {
	// Mailtext Platzhalter ersetzen
	$('#mailtext').val($('#mailtext').val().replace(last_recipient_name, $('#recipient_name').val()));
	$('#mailtext').val($('#mailtext').val().replace(last_sender_name, $('#sender_name').val()));
	last_recipient_name = $('#recipient_name').val();
	last_sender_name = $('#sender_name').val();
	
	$('#tell-a-friend_step1').hide('slow');
	$('#tell-a-friend_step2').show('slow');
}

function tellAfriend_go_step3() {
	var url = '/fileadmin/uhlsport/php/tell_a_friend_ajax.php';
	$.post(url, { 
			sender_name: $('#sender_name').val(), 
			sender_email: $('#sender_email').val(),
			recipient_name: $('#recipient_name').val(),
			recipient_email: $('#recipient_email').val(),
			mailtext: $('#mailtext').val()
		}, function(json){
			$('#tell-a-friend_step2').hide('slow');
			if(json.ok) {
				$('#errors').hide();
				$('#tell-a-friend_step3').show('slow');
			} else {
				$('#errors').show();
				$('#tell-a-friend_step1').show('slow');
			}
	}, 'json');
}

$(window).resize(function(){
	//Zentrieren der Details
	var windowWidth 	= $(window).width();
	var detailsWidth	= 440+440+10;
	
	$('div#previous-product').width(((windowWidth - detailsWidth)/2)-10);
	$('div#next-product').width(((windowWidth - detailsWidth)/2)-10);
	
	if (window.console && window.console.log)
		window.console.log('[zentrierenDetails] ' + windowWidth + ' zu ' + detailsWidth + ' max: '+(windowWidth - detailsWidth)/2);
});

