var imgnum1=1;
var imgnum2=1;
function imagerun()
{
   imgnum1 = imgnum2;
   imgnum2 = imgnum2+1;
   if(imgnum1 >= $('#book img').length)
   { imgnum1 = $('#book img').length; imgnum2=1; }
   $('#book').animate({  opacity: 0.75  }, 250, function() { $("#image" + imgnum1).hide(); $("#image"+imgnum2).show(); }).animate({  opacity: 1  }, 250, function() {});
}

var speed = 5000;
var MyMar;

$(document).ready(function(){
  MyMar=setInterval(imagerun,speed);

  $("#book").mouseover(function() {
    clearInterval(MyMar);
  })

  $("#book").mouseout(function() {
    MyMar=setInterval(imagerun,speed);
  })
});



var pl_imgnum1=1;
var pl_imgnum2=1;


function pl_imagerun()
{
   pl_imgnum1 = pl_imgnum2;
   pl_imgnum2 = pl_imgnum2+1;
   if(pl_imgnum1 >= $('#product_highlight_box a').length)
   { pl_imgnum1 = $('#product_highlight_box a').length; pl_imgnum2=1; }

   $('#product_highlight_box').animate({  opacity: 0.75  }, 250, function() { 
  
   $("#product_highlight_box a").eq(pl_imgnum1-1).hide();
   $("#product_highlight_box a").eq(pl_imgnum2-1).show();
   $(".pagenum").eq(pl_imgnum2-1).css('background-positionY',"0px");
   $(".pagenum").eq(pl_imgnum1-1).css('background-positionY',"-30px");

   }).animate({  opacity: 1  }, 250, function() {});
}

var pl_speed = 3000;
var pl_MyMar;

$(document).ready(function(){
  $(".pagenum").eq(0).css('background-positionY',"0px");
  $("#product_highlight_title .pagenum").mouseover(function() {
   myindex = $("#product_highlight_title .pagenum").index($(this))
   $(".pagenum").eq(pl_imgnum2-1).css('background-positionY',"-30px");
   $(".pagenum").eq(myindex).css('background-positionY',"0px");
   $("#product_highlight_box a").eq(pl_imgnum2-1).hide();
   $("#product_highlight_box a").eq(myindex).show();


   pl_imgnum2 = myindex + 1;
  })





  pl_MyMar=setInterval(pl_imagerun,speed);
  $("#product_highlight_box, .pagenum").mouseover(function() {
    clearInterval(pl_MyMar);
  }).mouseout(function() {
    pl_MyMar=setInterval(pl_imagerun,pl_speed);
  })








});





var timers;
$(function() {

   $('.item').hover(function()
   { 
     $("#" + this.id + "_box").addClass('itemhover');
     $("#" + this.id + "_box a:first").css({'color':'#9c2486'});
   }, function()
   { 
     $("#" + this.id + "_box").removeClass('itemhover');
     $("#" + this.id + "_box a").css({'color':'#505050'});
   }); 

   $('.menu ul li').hover(function()
   { 
     $(this).find('a').css({'color':'#9c2486'});
   }, function()
   { 
     $(this).find('a').css({'color':'#505050'});
   }); 

   $('.menu').hover(function()
   { 
     $(this).find("a").eq(0).css({'color':'#9c2486'});
   }, function()
   { 
     $(this).find("a").eq(0).css({'color':'#505050'});
   }); 
});


$(function(){
	//Get our elements for faster access and set overlay width
	var div = $('div.sc_menu'),
		ul = $('ul.sc_menu'),
		ulPadding = 2;
	
	//Get menu width
	var divWidth = div.width();
 
	//Remove scrollbars	
	div.css({overflow: 'hidden'});
	
	//Find last image container
	var lastLi = ul.find('li:last-child');
	
	//When user move mouse over menu
	div.mousemove(function(e){
		//As images are loaded ul width increases,
		//so we recalculate it each time
		var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;	
		var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;
		div.scrollLeft(left);
	});
});


$(function(){
  var timers;
  $(".btm_menu").mouseenter(function(){
    timers=setTimeout(function()
    {
	      $(".sc_menu").show();
    },500);

  }).mouseleave(function(){
    clearTimeout(timers)
    $(".sc_menu").hide();
  });
  
});



function producthighlight(theURL)
{
  open_win = window.open(theURL,'producthighlight','scrollbars=yes,resizable=yes,location=yes,width=970,height=950');
  open_win.focus();
}


var ginum = 1;
function GIpage(page)
{
  if(page == 'Prev')
  {
    if(ginum > 1){ ginum -= 1; }
    page = ginum;
  }
  if(page == 'Next')
  {
    if(ginum < maxginum){ ginum += 1; }
    page = ginum;
  }
  page = parseInt(page);
  ginum = page;
  $("#GI .GIBox").hide();
  $("#GI .GIBox").eq(page-1).show();
  $(".GInum a").css({'color':''});
  $(".GInum a").eq(page).css({'color':'red'});
}

var sgnum = 1;
function SGpage(page)
{
  if(page == 'Prev')
  {
    if(sgnum > 1){ sgnum -= 1; }
    page = sgnum;
  }
  if(page == 'Next')
  {
    if(sgnum < maxsgnum){ sgnum += 1; }
    page = sgnum;
  }
  page = parseInt(page);
  sgnum = page;
  $("#SG .SGBox").hide();
  $("#SG .SGBox").eq(page-1).show();
  $(".SGnum a").css({'color':''});
  $(".SGnum a").eq(page).css({'color':'red'});
}

$(document).ready(function()
{
 $("#bottom_tab_3").mouseenter(function(){
  if($("#GI").html() == "")
  {
   $.ajax({
             type: "get",
              url: "index.php",
             data: {	   action : "giftideas"	   },
         dataType: 'html',
          success: function(data)
                   {
			$("#GI").html(data);
			GIpage(1);
		   }
         });
  }
 })

 $("#bottom_tab_2").mouseover(function()
 {
  if($("#SG").html() == "")
  {
   $.ajax({
             type: "get",
              url: "index.php",
             data: {	   action : "suggest"	   },
         dataType: 'html',
          success: function(data)
                   {
			$("#SG").html(data);
			SGsearch('xx_road');
		   }
   });
  }
 })
});


function SGsearch(searchkeyword)
{
   $.ajax({
             type: "get",
              url: "index.php",
             data: {	   action : "suggest_search",
			  keyword : searchkeyword
		   },
         dataType: 'html',
          success: function(data)
                   {
			$("#SGshow").html(data);
			sgnum = 1;
			SGpage(sgnum);
		   }
   });
}


/* BOTTOM MENU */

$(document).ready(function(){
  $(".bottom_tabs_menu span:first").addClass("current");
  $(".bottom_tabs_menu ul:not(:first)").hide();
  $(".bottom_tabs_menu span").click(function()
  {
    $(".bottom_tabs_menu span").removeClass("current");
    $(this).addClass("current");
    $("#bottom_tabs ul").hide();
    $("."+$(this).attr("id")).show();
  });
});


function search(keyword)
{
  url = "search.php?keyword=" +  encodeURI(keyword)  + "#search";
  window.location = url;
}
