// JavaScript Document

$(document).ready(function(){
	var welcomeCycle;
	var sponsorsCycle;
        //var isMouseOut = true;
	initAll();
});

function initAll(){
	initWelcomeCycle();
	initSponsorCycle();
        setCoundown();
        setFormFocusEvent();
        setUpClickEvents();
	setUpHoverEvents();
        //setUpScrollEvents();
        //initUpNavLinks();
	setUpWelcomeAd();
        //initDropShadows();
}

/*function initUpNavLinks(){
    $('#menuList li a').each(function(){
        var locStr = window.location.href;
        var navStr = $(this).attr('href');
        if(locStr.indexOf(navStr) != -1){
            if($(this).parent().attr('id') != 'home'){
                $(this).addClass('selected');
            }
        }
    });
}*/

function setUpClickEvents(){
    $("#welcomeList li").click(function(){
        var myLink = $(this).children('div').children('p.subtext').children('a').attr('href');
        window.location = myLink;
        //alert('clicked');
    });
}

function setUpHoverEvents(){
	/*var textColor;
	$('ul#menuList li').hover(
	  function () {
		textColor = $(this).children('a').css('color');
		$(this).addClass('hoverSelected');
		$(this).children('a').css('color','#FFFFFF');
	  },
	  function () {
                alert(textColor);
		$(this).removeClass('hoverSelected');
		//Convert to uppercase for IE6
		$(this).children('a').css('color',textColor.toUpperCase());
	  }
	);*/
}

function setUpScrollEvents(){
    $(window).scroll(function () {
        //remove then add drop shadow to Divs on scroll

       //$(".whiteBG").redrawShadow();
       //$(".titleDiv")redrawShadow();
      /*$(".whiteBG").dropShadow();
       $(".titleDiv").dropShadow({left  :  2,
                                    top     :  2,
                                    blur    :  2,
                                    opacity :  0.5,
                                    color   :  "black",
                                    swap    :  false
                                  });
    });*/
    })

}

function initDropShadows(){
    //add drop shadow to Divs 
    /*$(".whiteBG").removeShadow();
    $(".titleDiv").removeShadow();*/
    $(".whiteBG").dropShadow();
    $(".titleDiv").dropShadow({left  :  2,
                                    top     :  2,
                                    blur    :  2,
                                    opacity :  0.5,
                                    color   :  "black",
                                    swap    :  false
                                  });
}

function setCoundown(){
	var rotwDate = new Date();
	rotwDate = new Date(2011, 7 - 1, 9);
	$('#defaultCountDown').countdown({until: rotwDate,
		layout: 'Countdown to festival... <span class="countDownDigits">{dn}</span> {dl} <span class="countDownDigits">{hn}</span>  {hl} <span class="countDownDigits">{mn}</span>  {ml} <span class="countDownDigits">{sn}</span>  {sl}'
	});
}

function setUpWelcomeAd(){
	 //When mouse rolls over
	 $("#welcomeList li").mouseover(function(){
                 //isMouseOut = false;
                 welcomeCycle.cycle('pause');
		 $(this).stop().animate({width:'288px'},{queue:false, duration:1000, easing: 'easeOutQuart'})
	 });

	 //When mouse is removed
	 $("#welcomeList li").mouseout(function(){
               // isMouseOut = true;
                welcomeCycle.cycle('resume');
		 $(this).stop().animate({width:'21px'},{queue:false, duration:1000, easing: 'easeOutQuart'})
	 });
}

function initWelcomeCycle(){
	welcomeCycle = $('#welcomeShow').cycle({fx: 'fade', pause: 1, before: onBefore});
}

function initSponsorCycle(){
	sponsorsCycle = $('.sponsors').cycle({fx: 'scrollLeft', pause: 1});
        //Stop rotation until sponsors are confirmed
        //sponsorsCycle.cycle('pause');
}

function onBefore(currSlideElement, nextSlideElement, options, forwardFlag) {
	//alert($(currSlideElement).eq());
	var idx = $('#welcomeShow img').index(nextSlideElement);

        
	$("#welcomeList li").stop().animate({width:'21px'},{queue:false, duration:500, easing: 'easeOutQuart'});
        openSlide(idx);
}

function openSlide(idx){
    //if(isMouseOut){
	$("#welcomeList li").eq(idx).stop().animate({width:'288px'},{queue:false, duration:500, easing: 'easeOutQuart'});
    //}
}

function addTweets(){

	$("#tweetsDiv .contentDiv").getTwitter({
		userName: "ROTW_2010",
		numTweets: 4,
		loaderText: "Loading tweets...",
		slideIn: false,
		showHeading: false,
		headingText: "Latest Tweets",
		showProfileLink: false
	});
}

function setFormFocusEvent(){
    $('#contactDiv input, #contactDiv textarea').focus(function(){
        $(this).val('');
    });
}
