/* -- GOOGLE +1 BUTTON SCRIPT -- */
(function() {
    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
    po.src = 'https://apis.google.com/js/plusone.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
  })();


function blurInput(el) {
	if (el.value == "name" || el.value == "example@example.com" || el.value == "message" || el.value == "" ) {
		el.style.color = "#999999";
		}

//	setField(el);
	}

function focusInput(el) {
	el.style.color = "#202020";
//	clearField(el);
	}



/* -- UI SCRIPTS -- */
$(document).ready(function(){


	// SHOP SUBMENU
	$('#shop-sub').hover(function(){
		$('#shop-menu').show();
		$('#shop-sub div').attr('class', 'menu-over');
		},
		function(){
			$('#shop-menu').hide('slow');
			$('#shop-sub div').attr('class', 'menu-off');
		});


	// 101 THINGS SUBMENU
	$('#things-sub').hover(function(){
		$('#things-menu').show();
		$('#things-sub div').attr('class', 'menu-over');
		},
		function(){
			$('#things-menu').hide('slow');
			$('#things-sub div').attr('class', 'menu-off');
		});

	// DESELECT ALL BUTTONS ON HOME PAGE
	function deselectAll () {
		$('.index li').removeClass("selected");
		}


/*

SLIDE EDITS HAPPEN IN TWO PLACES -- TILL FUNCTIONS COMBINED

*/


	// CONTENT SUBMENU IMAGE/ACTION BUTTON CHANGES
	$('.index-sub').click(function(){

		var theID = $(this).attr("id");
		var bgImg = document.getElementById('background');
		var actionButton = document.getElementById("action-button");

		// DESELECT ALL SELECTED BUTTONS FIRST
		deselectAll();

		switch (theID) {
			case "shop-button":

			actionButton.innerHTML = "shop now";
			actionButton.href = "shop-fall-2011/";
			actionButton.target = "";

			$(bgImg).animate({
				left:"0px"
				}, 300);

			break;


			case "lbmd-button":

/* 			actionButton.innerHTML = "shop LBMDs"; */
			actionButton.innerHTML = "sparkle";
			actionButton.href = "http://moreofmematernity.com/products/new-arrivals-fall-2011/";
			actionButton.target = "";

			$(bgImg).animate({
				left:"-955px"
				}, 300);

			break;


			case "pop-button":

			actionButton.innerHTML = "shop colorfully";
			actionButton.href = "http://moreofmematernity.com/products/new-arrivals-fall-2011/";
			actionButton.target = "";

			$(bgImg).animate({
				left:"-1900px"
				}, 300);
			break;


/* 			SLIDE 3 v1

			case "versatile-button":

			actionButton.innerHTML = "be versatile";
			actionButton.href = "one-dress-different-ways/";
			actionButton.target = "";

			$(bgImg).animate({
				left:"-1900px"
				}, 300);
			break;

*/


			case "pinterest":

			actionButton.innerHTML = "my pinterest";
			actionButton.href = "http://pinterest.com/mom101things/";
			actionButton.target = "_blank";

			$(bgImg).animate({
				left:"-2855px"
				}, 300);

			break;

			}


		// SELECT THE BUTTON THAT WAS CLICKED
		var theLI = document.getElementById(theID).offsetParent;
		theLI.className = "selected";

		return false;


		});



	// START THE SLIDESHOW IF ON THE HOME PAGE
	if (document.getElementById('background')) {
		if (document.getElementById('background').className = "index-auto") {
			setTimeout(autoSlide,6000);
			}
		}


	/* AUTO SLIDESHOW */
	function autoSlide() {

		var bgImg = document.getElementById('background');
		var actionButton = document.getElementById("action-button");

		// USE THE ACTION BUTTON TEXT TO DETERMINE THE NEXT SLIDE
		var abText = document.getElementById("action-button").innerHTML;

		// DESELECT ALL SELECTED BUTTONS FIRST
		deselectAll();

		switch (abText) {


			case "shop now":

/* 			actionButton.innerHTML = "shop LBMDs"; */
			actionButton.innerHTML = "sparkle";
			actionButton.href = "http://moreofmematernity.com/products/new-arrivals-fall-2011/";
			actionButton.target = "";
			theID = "lbmd-button";

			$(bgImg).animate({
				left:"-955px"
				}, 600);

			setTimeout(autoSlide,6000);

			break;


			case "sparkle":

			actionButton.innerHTML = "shop colorfully";
			actionButton.href = "http://moreofmematernity.com/products/new-arrivals-fall-2011/";
			actionButton.target = "";
			theID = "pop-button";

			$(bgImg).animate({
				left:"-1900px"
				}, 600);

			setTimeout(autoSlide,6000);

			break;



			case "shop colorfully":

			actionButton.innerHTML = "my pinterest";
			actionButton.href = "http://pinterest.com/mom101things/";
			actionButton.target = "_blank";
			theID = "pinterest";

			$(bgImg).animate({
				left:"-2855px"
				}, 600);

			setTimeout(autoSlide,6000);

			break;



			case "my pinterest":
			actionButton.innerHTML = "shop now";
			actionButton.href = "shop-fall-2011/";
			actionButton.target = "";
			theID = "shop-button";

			$(bgImg).animate({
				left:"0px"
				}, 600);

			setTimeout(autoSlide,6000);

			break;



			}


		// SELECT THE BUTTON THAT WAS CLICKED
		var theLI = document.getElementById(theID).offsetParent;
		theLI.className = "selected";



		return false;

		}


	});






/* 			SLIDE 2 V1

			case "shop LBMDs":

			actionButton.innerHTML = "be versatile";
			actionButton.href = "one-dress-different-ways/";
			actionButton.target = "";
			theID = "versatile-button";

			$(bgImg).animate({
				left:"-1900px"
				}, 600);

			setTimeout(autoSlide,6000);

			break;

 */



/*			SLIDE 3 V1
			case "be versatile":

			actionButton.innerHTML = "my pinterest";
			actionButton.href = "http://pinterest.com/mom101things/";
			actionButton.target = "_blank";
			theID = "pinterest";

			$(bgImg).animate({
				left:"-2855px"
				}, 600);

			setTimeout(autoSlide,6000);

			break;
*/
















/* BELOW ARE ALL ORIGINAL SCRIPTS -- INCLUDING SOME SLIDESHOW STUFF THAT WEMIGHT USE */




var _slides;
var _duration = 7500;
var _all_slides = [];
var _autoplay = true;
var _current;
var z_index = 0;
function initSlideshow()
{
	if(document.getElementById('gallery'))
	{
		_current = 0;
		_all_slides = $("#gallery li");
		_slides = _all_slides.length;
		if(_slides>1)
		{
			_all_slides.css({"position": "absolute", "top": 30, "left": 31, "opacity": 0, "z-index": 0});
			$(_all_slides[0]).css({"opacity": 1, "z-index": 1});

			setTimeout('rotate(' + 0 +')', _duration);
		}
	}
}
function rotate(_index)
{
	if(_autoplay)
	{
		$(_all_slides[_index]).animate({"opacity": 0});
		if(_index==_slides-1)
			_index=-1;

		$(_all_slides[++_index]).css({"z-index": ++z_index});
		$(_all_slides[_index]).animate({"opacity": 1});

		_current = _index;
		setTimeout('rotate(' + _index + ')', _duration);
	}
}

function initProductSlider()
{
	if(document.getElementById('big-image'))
	{
		var slides;
		var current = 0;
		var all_slides = $("#big-image li");
		slides = all_slides.length;
		all_slides.css({"position": "absolute", "top": 23, "left": 19, "opacity": 0});
		$(all_slides[0]).css({"opacity": 1});
		all_slides[0].parentNode.style.height = all_slides[0].clientHeight + 49 + "px";

		var all_thumbs = $('#thumbnails li');
		$(all_thumbs).each(function(el)
		{
			$(all_thumbs)[el].href = 'javascript:;';
			$(all_thumbs[el]).click(function()
			{
				if(el!=current)
				{
					$(all_slides[current]).fadeTo("slow", 0);
					$(all_slides[el]).fadeTo("slow", 1);
					$(all_slides[el]).parent().animate({height: all_slides[el].clientHeight + 49 + "px"}, { duration: 200, queue:false });
					current = el;
				}
			});
		});
	}
}

if (window.addEventListener)
{
	window.addEventListener("load", initSlideshow, false);
	window.addEventListener("load", initProductSlider, false);
}
else if (window.attachEvent)
{
	window.attachEvent("onload", initSlideshow);
	window.attachEvent("onload", initProductSlider);
}
