sliders = new Array();
sliders['#slider_colors'] = new Array(5, 1);
sliders['#slider_morepic'] = new Array(4, 1);

zoom_hs = null;


$(document).ready(
		function()
		{
			//showElm();			
			
			for ( id in sliders)
			{
				if ( $(id).length)
				{
					var anzPic = sliders[id][0];
					var step = sliders[id][1];
					//alert('ID:' + id);
					setSlider( anzPic, id, step);
				}				
			}
			if ( $('#to_basket_btn').length)
			{
				setBasketBtn();
			}
			if ( $('#show_bookmark'))
			{
				$('#show_bookmark').click( function ()
						{
							if( $( '#bookmark_layer').hasClass( 'open'))
							{
								$( '#bookmark_layer').removeClass( 'open');
								$( this).removeClass( 'active');
							}
							else
							{
								$( '#bookmark_layer').addClass( 'open');
								$( this).addClass( 'active');
							}
							blur();
							return false;
						});
			}
			
			$( '#bookmark_layer').hover( function ()
						 {
							 $( this).addClass( 'open');
							 $('#show_bookmark').addClass( 'active');
						 },
						 function ()
						 {
							 $( this).removeClass( 'open');
							 $('#show_bookmark').removeClass( 'active');
						 }
						 );
			
			setSaving();	
			setVariantSlider();
			
			//setZoomify();
		}
);

function setZoomify()
{
	$( '#zoom_tip a').hide();
	$( '#zoom_tip a').click( function () { $( '#zoom_tip a').hide(); });
			
	$( '#detail_snippet .pic').hover( function()
		{
			if( $( '#zoomtpl').length)
			{
				imgTop = $( '#product_img').position().top;
				imgLeft = $( '#product_img').position().left;
				imgW = $( '#product_img').width();
				imgH = $( '#product_img').height();
				centerX = imgLeft + (imgW/2) - ( $( '#zoom_tip a').width()/2) ;
				centerY = imgTop + (imgH/2) - ( $( '#zoom_tip a').height()/2) ;
				
				
				$( '#zoom_tip a').css( 'top', parseInt( centerY)+'px');
				$( '#zoom_tip a').css( 'left', parseInt( centerX)+'px');
				
				if ( $( '#zoom_tip a').css( 'display') ==  'none' )
				{
					$( '#zoom_tip a').show( 'slow');
				}
			}
		},
		function()
		{
			//$( '#zoom_tip a').hide( 'slow');	
		}
	);
}

function setVariantSlider()
{
	$( '#slider_colors li a').not( '.active', this).hover( function()
											  {
												  $( this).addClass( 'active');
											  },
											  function()
											  {
												  $( this).removeClass( 'active');
											  });
}


function showElm()
{
	$( '.variant').css( 'display', 'block');
	$( '.rating_box').css( 'display', 'block');
	$( '.shipping').css( 'display', 'block');
	$( '.price').css( 'display', 'block');
	$( '.saving').css( 'display', 'block');
	$( '.more_colors').css( 'display', 'block');
	$( '.am_minus').css( 'display', 'inline');
	$( '.am_plus').css( 'display', 'inline');
	$( '.morePic').css( 'display', 'block');
}


function setZoomHS( )
{
	//hs.lang.creditsText = title;
	//hs.creditsHref = 'javascript: return false;';
	hs.showCredits = false;

	//hs.width = 500;
	//hs.height = 600;
	
	hs.allowWidthReduction = true;
	hs.allowHeightReduction = true;
	
	hs.allowSizeReduction = true;
	
}

function loadZoomify( actA)
{
	$( '#zoom_img').hide();
	$( '#super_zoom').show();
	/*$( '#super_zoom').css( 'visibility', 'visible');
	$( '#super_zoom').css( 'height', '453px');*/
	
	$( '#zoom_img').hide();
	w = $( '#super_zoom').width();
	h = $( '#super_zoom').height();
	ulW = $( '#zoom_cnt .more_zoom_pics').width();
	resetHsZoomify( w+ulW, h);
	
	$( '#zoom_cnt .other_zooms a').removeClass( 'active');
	$( actA).addClass( 'active');
}

function imgLoad( actA)
{
	/*
	$( '#zoom_img').load(
						 function()
						 {
							 $( '#super_zoom').hide();
							 w = $(this).width();
							 h = $(this).height();
							 ulW = $( '#zoom_cnt .more_zoom_pics').width();
							 resetHsZoomify( w+ulW, h);
							 $( '#zoom_img').show();
						 }
	);
	*/
	$( '#zoom .tabs li').removeClass( 'active');
	$( actA).parent().addClass( 'active');
}

function resetHsZoomify( w, h )
{	
	var exp = zoom_hs;
	/*
	var l = hs.expanders.length;
	var i = 0;

	while( i >= 0 && hs.expanders[i].a.id != 'hs_zoomify')
	{
		++i;
	}
	if ( i >= 0) exp = hs.expanders[i];
	*/
	if ( exp != null)
	{
		exp.resizeTo( w+40, h+60);
		exp.reflow();
	}
}

function setSaving()
{
	if ( $( '#saving_more2'))
	{
		$( '#saving_more2').click( function()
				{
					if ( $( '.payment_types').hasClass( 'open'))
					{
						$( '.payment_types').removeClass( 'open');
						$( this).removeClass( 'close');
					}
					else
					{
						$( '.payment_types').addClass( 'open');
						$( this).addClass( 'close');
					}
					this.blur();
					return false;
				});
	}
	if ( $( '#saving_more'))
	{
		$( '#saving_more').click( function()
				{
					if ( $( '.payment_types').hasClass( 'open'))
					{
						$( '.payment_types').removeClass( 'open');
                        $( this).html( saving_more_open);
                    }
					else
					{
                        $( '.payment_types').addClass( 'open');
                        $( this).html( saving_more_close);
                    }
                    return false;
				});
	}
}


function setDetailMenu( sShopurl, aid)
{
	$( '#detail_menu ul li a').click( function ()
			{
				ajax_load('on');
				tpl = $(this).attr('id') + '.tpl';
				liElm = $(this).parent();
				$('#detail_menu ul li').removeClass( 'open');
				$(liElm).addClass( 'open');
				$( "#details_bottom").load( sShopurl + "index.php?cl=dd_details_bottom&anid=" + aid + "&tpl=" + tpl, function () { ajax_load( 'off'); afterDetailMenuLoad( tpl); } );
				
				return false;
			});
}

function afterDetailMenuLoad( tpl)
{
	if( tpl == 'dd_details_bewertungen.tpl')
	{
		setHelpLayer();
	}
}

function showDDReview( sShopurl, aid)
{
	oBtn = $( '#dd_details_bewertungen');
	ajax_load('on');
	tpl = $( oBtn).attr('id') + '.tpl';
	liElm = $( oBtn).parent();
	$('#detail_menu ul li').removeClass( 'open');
	$(liElm).addClass( 'open');
	$( "#details_bottom").load( sShopurl + "index.php?cl=dd_details_bottom&anid=" + aid + "&tpl=" + tpl, function () { ajax_load( 'off'); afterDetailMenuLoad( tpl); } );
}

function setGalleryBox()
{
	$( '.gallery_box').hover( function ()
			{
		$('.to_detail', this).css( 'display', 'block');
			},
			function ()
			{
				$('.to_detail', this).css( 'display', 'none');
			});

}

