/********************************************************************
 * http://www.web-experts.gr (Custom javascript)
 *
 * Copyright (c) 2010
 * Powered by Web-Experts
 ********************************************************************/

/**
 * Setup CssDropDown for top menu
 */
$(document).ready(function()
{
	 
	$("td.menu").mouseenter(function()
	{	
		if ($("td.menu").index(this)>3)
		{
			return;	
		}
		$("div.cssdropdown",this).slideDown('medium');
		$(this).addClass("menuover");
	}) 
	.mouseleave(function()
	{	
		$(this).removeClass("menuover");
		menuOff();
	});	
});
function menuOff()
{
	$("div.cssdropdown *:animated").stop(true,true).hide();
	$("div.cssdropdown").each(function()
	{
		$(this).slideUp('fast');
	});	
}
/**
 * Setup for Nivo Slider
 */
$(document).ready(function()
{
	if ($('#nivo-slider').exists())
	{
		$('#nivo-slider').nivoSlider({
			animSpeed:500,
	        pauseTime:3000,
			controlNav:true,
			keyboardNav:true,
			pauseOnHover:true
		});
	}
});

/**
 * Setup for Fancy Box
 */
$(document).ready(function()
{
	$("a[rel=image-gallery]").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titlePosition' 	: 'over',
		'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
		    return '<span id="fancybox-title-over">Image ' +  (currentIndex + 1) + ' / ' + currentArray.length + ' ' + title + '</span>';
		}
	});
	$('.po_trigger').fancybox({ 'autoDimensions'	: false,'width':400,'height' : 'auto'});
	 $('.marquee').marquee('pointer').mouseover(function () {
            $(this).trigger('stop');
	}).mouseout(function () {
		$(this).trigger('start');
	});
});
/**
 * Setup for Specials Box
 */
if ($('#specials-box').exists())
{
	stepcarousel.setup({
		galleryid: 'specials-box',
		beltclass: 'specials-box-container',
		panelclass: 'specials-box-panel',
		autostep: {enable:false, moveby:1, pause:5000},
		panelbehavior: {speed:500, wraparound:true, persist:false},
		defaultbuttons: {enable: false, moveby: 1, leftnav: ['images/left.png', -35, 220], rightnav: ['images/right.png',-25, 220]},
		statusvars: ['sbCurrentPossition', 'sbStatus', 'sbTotal'],
		contenttype: ['inline']
	});
}

$(document).ready(function() 
{	
	if ($('#specials-box-previous').exists() && $('#specials-box-next').exists())
	{
		$('#specials-box-previous').click(function(){stepcarousel.stepBy('specials-box', -1); return false;});
		$('#specials-box-next').click(function(){stepcarousel.stepBy('specials-box', 1); return false;});
		$('#specials-box-previous').mouseenter(function(){$(this).addClass("mouseOver");}).mouseleave(function(){$(this).removeClass("mouseOver");});
		$('#specials-box-next').mouseenter(function(){$(this).addClass("mouseOver");}).mouseleave(function(){$(this).removeClass("mouseOver");});
	}
});
/**
 * Setup for What's New Box
 */
if ($('#whats-new-box').exists())
{
	stepcarousel.setup({
		galleryid: 'whats-new-box',
		beltclass: 'whats-new-box-container',
		panelclass: 'whats-new-box-panel',
		autostep: {enable:false, moveby:1, pause:5000},
		panelbehavior: {speed:500, wraparound:true, persist:false},
		defaultbuttons: {enable: false, moveby: 1, leftnav: ['images/left.png', -35, 220], rightnav: ['images/right.png',-25, 220]},
		statusvars: ['sbCurrentPossition', 'sbStatus', 'sbTotal'],
		contenttype: ['inline']
	});
}

$(document).ready(function() 
{	
	if ($('#whats-new-box-previous').exists() && $('#whats-new-box-next').exists())
	{
		$('#whats-new-box-previous').click(function(){stepcarousel.stepBy('whats-new-box', -1); return false;});
		$('#whats-new-box-next').click(function(){stepcarousel.stepBy('whats-new-box', 1); return false;});
		$('#whats-new-box-previous').mouseenter(function(){$(this).addClass("mouseOver");}).mouseleave(function(){$(this).removeClass("mouseOver");});
		$('#whats-new-box-next').mouseenter(function(){$(this).addClass("mouseOver");}).mouseleave(function(){$(this).removeClass("mouseOver");});
	}
});
/**
 * Setup for Tabs in Product Info page
 */
if ($('#product-info-page-tabs').exists())
{
	stepcarousel.setup({
		galleryid: 'product-info-page-tabs',
		beltclass: 'product-info-page-tabs-container',
		panelclass: 'product-info-page-tabs-panel',
		autostep: {enable:false, moveby:1, pause:500},
		panelbehavior: {speed:500, wraparound:true, persist:false},
		defaultbuttons: {enable: false, moveby: 1, leftnav: ['images/tab-arrow-left.png', -35, 220], rightnav: ['images/tab-arrow-right.png',-25, 220]},
		statusvars: ['piPageCurrentPossition', 'piPageStatus', 'piPageTotal'],
		contenttype: ['inline'],
		onslide:function(){
			for (i=1; i<=4; i++)
			{
				if (i==piPageCurrentPossition)
				{
					if ($("#product-info-tab-"+i).exists())
					{
						$("#product-info-tab-"+i).removeClass("product-info-tab-inactive");
						$("#product-info-tab-"+i).addClass("product-info-tab-active");
					}
				}
				else
				{
					if ($("#product-info-tab-"+i).exists())
					{
						$("#product-info-tab-"+i).removeClass("product-info-tab-active");
						$("#product-info-tab-"+i).addClass("product-info-tab-inactive");
					}					
				}
			 }
		}
	});
}

$(document).ready(function() 
{	
	if ($('#product-info-page-tabs').exists())
	{
		$('#product-info-tab-1').click(function(){stepcarousel.stepTo('product-info-page-tabs', 1); return false;});
		$('#product-info-tab-2').click(function(){stepcarousel.stepTo('product-info-page-tabs', 2); return false;});
		$('#product-info-tab-3').click(function(){stepcarousel.stepTo('product-info-page-tabs', 3); return false;});
		$("#product-info-tab-4").click(function(){stepcarousel.stepTo('product-info-page-tabs', 4); return false;});
		$('#product-info-tab-1').mouseenter(function(){$(this).addClass("mouseOver");}).mouseleave(function(){$(this).removeClass("mouseOver");});
		$('#product-info-tab-2').mouseenter(function(){$(this).addClass("mouseOver");}).mouseleave(function(){$(this).removeClass("mouseOver");});
		$('#product-info-tab-3').mouseenter(function(){$(this).addClass("mouseOver");}).mouseleave(function(){$(this).removeClass("mouseOver");});
		$('#product-info-tab-4').mouseenter(function(){$(this).addClass("mouseOver");}).mouseleave(function(){$(this).removeClass("mouseOver");});
	}
});
/**
 * Setup for Autocomplete
 */
$("#keywords").autocomplete("advanced_search_autocomplete.php", {
		width: 280,
		selectFirst: false,
		scroll: false,
		formatItem: function(row){
          var ret = '<div class="autocomplete">' + row[1] + '<div class="autocomplete_title_div">' + row[0] + '</div></div>';
          //ret += '<span class="image">' + row[1] + '</span>';
          return ret;
        },
        formatValue: function(row){
          return row[0]; // We only want the first value to be searched
        },		
	}).result(function(event, item, formatted) {
      $(this).parents().find('#quick_find').submit();
 	});
