$(document).ready(function() {
   if ($('.welcomeImage').children('div').is('#wordcycle')) {
      initializehero();
   }
   if ($('body').hasClass('blog')) {
      blogintegration();
   }
});


function initializehero () {

   howmanyverbsarethere = $('#wordcycle').children('ul.verbs').children('li').length;
   howmanyfullsarethere = $('#wordcycle').children('ul.fulls').children('li').length;
   
   randomverb=Math.floor(Math.random()*howmanyverbsarethere)
   randomfull=Math.floor(Math.random()*howmanyfullsarethere)
   
   $('#wordcycle').children('ul.verbs').children('li').css({'left': '0px'}).children('img').css({'opacity': '0'});
   $('#wordcycle').children('ul.verbs').children('li:eq('+randomverb+')').children('img').css({'opacity': '1'}).parent('li').addClass('active');
   $('#wordcycle').children('ul.fulls').children('li').css({'opacity': '0'});
   $('#wordcycle').children('ul.fulls').children('li:eq('+randomfull+')').css({'opacity': '1'}).addClass('active');

   heroprocess();

} // initializehero

function heroprocess() {

   $('#wordcycle').children('ul.verbs').children('li:eq('+randomverb+')').children('img').animate({'opacity': '1'}, {duration: 1750, easing: "linear"}).parent('li').animate({'left': '-150px'}, {duration: 5750, easing: "linear"}).addClass('active');

   verbloop = setInterval (function(){
      switchtheverb();
   }, 5250); //verbloop
   
   fullloop = setInterval (function(){
      switchthefull();
   }, 3500); //fullloop

} // heroprocess


function switchtheverb() {

   newrandomverb=Math.floor(Math.random()*howmanyverbsarethere)
   if (newrandomverb == randomverb) {
      switchtheverb();
   } else {
      randomverb = newrandomverb;
      $('#wordcycle').children('ul.verbs').children('li.active').removeClass('active').children('img').animate({'opacity': '0'}, 500).parent('li').animate({'opacity': '1'}, 500).animate({'left': '0px'}, 10);
      $('#wordcycle').children('ul.verbs').children('li:eq('+randomverb+')').children('img').animate({'opacity': '1'}, {duration: 1750, easing: "linear"}).parent('li').animate({'left': '-150px'}, {duration: 5750, easing: "linear"}).addClass('active');
   } //if same as old

} //switchtheverb



function switchthefull() {

   newrandomfull=Math.floor(Math.random()*howmanyfullsarethere)
   if (newrandomfull == randomfull) {
      switchthefull();
   } else {
      randomfull = newrandomfull;
      $('#wordcycle').children('ul.fulls').children('li.active').removeClass('active').animate({'opacity': '0'}, 500);
      $('#wordcycle').children('ul.fulls').children('li:eq('+randomfull+')').animate({'opacity': '1'}, 500).addClass('active');
   } //if same as old

} //switchthefull






function blogintegration() {

	$.ajax({
		type: "GET",
		url: "/store/default.aspx",
		dataType: "html",
		success: function(storehtml) {
			$(storehtml).find('#storeHeader').each(function(i){
   			$(this).appendTo('.headercontainer');
			});
/*
			$(storehtml).find('.hpright').each(function(i){
   			$(this).appendTo('#rightSidebarPanel')
			});
*/
			$(storehtml).find('#leftSidebarPanel').children('div').each(function(i){
   			$(this).appendTo('#leftSidebarPanel')
			});
			$(storehtml).find('#footer').each(function(i){
   			$(this).appendTo('#feet');
			});

			$('.headercontainer').find('#ctl00_wpm_HomePage_ctl00_SearchPanel').remove();

         $('a.storelink').each(function(){
//   			$(this).attr({'href': '/store/'+$(this).attr('href')});
         }); //each a.storelink
			
		}
	}); //ajax



//   $(".headercontainer").load("/store #storeHeader");
//   $('#rightSidebarPanel').load('/store .hpright');
//   $('#leftSidebarPanel').load('/store #ctl00_wpm_HomePage_ctl01_MainPanel');
} //blogintegration







