// JavaScript Document
$(window).load(function(){
	
	$('div.description').each(function(){
		
		$(this).css('opacity', 0);
		$(this).css('width', $(this).siblings('img').width());
		$(this).parent().css('width', $(this).siblings('img').width());
		$(this).css('display', 'block');
	});

	$('div.wrapper').hover(function(){
		$(this).children('.description').stop().fadeTo(500, 0.7);

	},function(){
		$(this).children('.description').stop().fadeTo(500, 0);
	});

});

//drop down
$(document).ready(function(){

$("ul#subnav li.BV_view a").click(
  function () {
    $('#storydropdown').slideToggle('slow'); 

	//},function(){
		//$('#storydropdown').slideUp(5000);


	 });


  $('#morestories').click(
  function () {
    $('#morestories_hidden').slideToggle('slow');
  });

 $('ul#storydropdown li a').click(
  function () {
    $('#storydropdown').hide();
	$('#grid_container').css('margin-left','0px');
	$('#prev').hide();
	  });

 $('.thumbnail_container a img').click(
	  function () {
	 $('#storydropdown').hide();
 });

});



//random feature story change 
function randomstory(storydetail) {
      var stories = document.getElementsByTagName("div");
            for(var x=0; x<stories.length; x++) {
                  name = stories[x].getAttribute("name");
                  if (name == 'stories') {
                        if (stories[x].id == storydetail) {
                        stories[x].style.display = 'block';
                  }
                  else {
                        stories[x].style.display = 'none';
                  }
            }
      }
}





(function($){
 $.fn.PDP= function(options) {

  var newdefaults = {
	leftImageID: "#leftarrow",
	rightImageID: "#rightarrow",
	newnoOfContainer: $(".firstproductinfo").length,
	newcontainerW: 200,
	newduration: 1000
  };
  var newop = $.extend(newdefaults, options);
  var newpathObj = $('#product_container').children();
  var newi = 0;
  return this.each(function() {
							
						$(window).load(function(){	
							if($(".firstproductinfo").length==1)	
			{
				$('#rightarrow').hide();
				$('#leftarrow').hide();
				
			}
			
		});
						
						
		$(this).click(function()
		{
			
			if(this.id==newop.leftImageID.replace("#",""))
			{
				$('#rightarrow').show();
				newi++;
				if(newi > 0)
				{newi--;}
				if(newi == 0)
				{$('#leftarrow').hide();$('#rightarrow').show();}
						}
			else if(this.id==newop.rightImageID.replace("#",""))
			{
				$('#leftarrow').show();
				newi--;
				if(newi<(0-(newop.newnoOfContainer-1)))
				{newi++;}
					if ($(".firstproductinfo").length == 3){	if(newi == -2){$('#rightarrow').hide();}}
					if ($(".firstproductinfo").length == 2){	if(newi == -1){$('#rightarrow').hide();}}
												}
			$("div#product_container").animate({marginLeft: newi*newop.newcontainerW+"px"},'medium');
			
		});
  });
 };
})(jQuery);

$(function(){
$('div#leftarrow, div#rightarrow').PDP();
});


(function($){
$.fn.review= function(options) {

  var Rdefaults = {
                RleftImageID: "#home_prev",
                RrightImageID: "#home_next",
                RnoOfContainer:$(".review_product").length-1,
                RcontainerW: 210,
                Rduration: 1000
  };
  var Rop = $.extend(Rdefaults, options);
  var RpathObj = $('#review_container').children();
  var Ri = 0;
 return this.each(function() {
                                
                               $(this).click(function()
                                {
                                                if(this.id==Rop.RleftImageID.replace("#",""))
                                                { $('#home_next').show();
                                                                Ri++;
                                                                if(Ri > 0)
                                                                {Ri--;
                                                                }
                                                                
                                                                if(Ri == 0){$('#home_prev').hide();$('#home_next').show();}
                                                                                                }
                                                else if(this.id==Rop.RrightImageID.replace("#",""))
                                                {
                                                                $('#home_prev').show();
                                                                Ri--;
                                                                if(Ri<(0-(Rop.RnoOfContainer-1)))
                                                                {                                                                              
                                                                Ri++;
                                                                
                                                                                                                                }
                                                                                                                                
                                                                                                                                if(Ri == -18){                $('#home_next').hide();$('#home_prev').show();}
                                                                                                                                                                
                                                                                                }
                                                $("div#review_container").animate({marginLeft: Ri*Rop.RcontainerW+"px"},'medium');
                                                
                                });

  });
};
})(jQuery);

$(function(){
$('div#home_prev, div#home_next').review();
});


$(document).ready(function(){
 $('#grid_container').find('.box:first').addClass('first_child');
 $('#grid_container').find('.box:last').addClass('last_child');
 
});
//Grid slide
(function($){
 $.fn.thumbnails= function(options) {

  var defaults = {
	prevImageID: "#prev",
	nextImageID: "#next",
	noOfContainer: $(".box").length,
	containerW: 980,
	duration: 1000
  };
  var op = $.extend(defaults, options);
  var pathObj = $('#grid_container').children();
  var i = 0;
  return this.each(function() {
			
			$(window).load(function(){	
							if($(".box").length==1)	
			{
				$('#prev').hide();
				$('#next').hide();
				
			}
			
		});
		
		$(this).click(function()
		{
			if(this.id==op.prevImageID.replace("#",""))
			{$('#next').show();
				i++;
				if(i > 0)
				{i--;}
				if(i==0){$('#prev').hide();$('#next').show();}
						}
			else if(this.id==op.nextImageID.replace("#",""))
			{$('#prev').show();
				i--;
				if(i<(0-(op.noOfContainer-1)))
				{ 
					i++;}
					if(i==-($(".box").length-1)){$('#next').hide();$('#prev').show();}
			}
			$("div#grid_container").animate({marginLeft: i*op.containerW+"px"},'slow');
			var thumbX = $(".box").length; 
			var thumbY = 980;
			 $('#grid_container').css({'width': thumbX*thumbY + 'px'});
		});
  });
 };
})(jQuery);

$(function(){
$('div#prev, div#next').thumbnails();
});
	
//thick box
function gradient(id, level)
{
	var previewbox = document.getElementById(id);
	previewbox.style.opacity = level;
	previewbox.style.MozOpacity = level;
	previewbox.style.KhtmlOpacity = level;
	previewbox.style.filter = "alpha(opacity=" + level * 100 + ")";
	previewbox.style.display="block";
	return;
}


function fadein(id) 
{
	var level = 0;
	while(level <= 1)
	{
		setTimeout( "gradient('" + id + "'," + level + ")", (level* 1000) + 10);
		level += 0.01;
	}
}


// Open the lightbox


function openbox(imgUrl,formtitle, fadin)
{
  var imageurl = imgUrl;
  document.getElementById('image_popup').src=imageurl;
  var previewbox = document.getElementById('previewbox'); 
  document.getElementById('overlay').style.display='block';

  
  
  if(fadin)
  {
	 gradient("previewbox", 0);
	 fadein("previewbox");
  }
  else
  { 	
    previewbox.style.display='block';
  }  	
}




// Close the lightbox

function closebox()
{
   document.getElementById('previewbox').style.display='none';
   document.getElementById('overlay').style.display='none';
}
///home slide




$(document).ready(function(){
            $('img.tag_product_img').imgscale({
              parent : '.tag_product_storyimg',
              fade : 1000
            });
          });
//image scale
$(document).ready(function(){
  $('img.user_image').imgscale({
    parent : '.image_container',
    fade : 1000
  });
  
  $('img.user_thumbnail').imgscale({
    parent : '.thumbnail_container',
    fade : 1000
  });

 
});



