$(function(){
	wuyes.init();
});

wuyes = {
	isSpanish: false,
	currHomeEffect: null,
	artistFading: false,
	init:function(){
		var wUrl = document.location.href.split("/");
		for(var x=0; x<wUrl.length; x++){
			if(wUrl[x] == "es"){
				wuyes.isSpanish = true;
			}
		}
		
		
		$("a[rel='external']").unbind("click").click(function(){
			window.open(this.href, "_blank");
			return false;
		}).each(function(){
			$(this).attr("title","External link - will open in a new window");
		});
		
		if(document.getElementById("musicEffectInner")){
			var wimpyConfigs560 = new Object();
			wimpyConfigs560.wimpySwf="http://www.awal.com/Rave/rave.swf";
			wimpyConfigs560.wimpyApp="http://www.awal.com/Rave/wu2.xml";
			wimpyConfigs560.wimpyWidth="455";
			wimpyConfigs560.wimpyHeight="315";
			wimpyConfigs560.wimpyReg=" NGpla3F1JTNCJTI0TyU3RTklMjclM0FjZk0lNUMlN0IlNUNHZVBoazYyJTVD";
			wimpyConfigs560.wimpySkin="http://www.awal.com/Rave/WU/WU_Skin Machine/Layout from Profero.xml";
			wimpyConfigs560.autoAdvance="no";
			wimpyConfigs560.wimpyHTMLpageTitle="Yes! Effect Player";
			wimpyConfigs560.tptBkgd="yes";
			wimpyConfigs560.bkgdColor="#FFFFFF";
			makeWimpyPlayer(wimpyConfigs560, "musicEffectInner");
		}
		
		if(document.getElementById("musicPopupInner")){
			var wimpyConfigs560 = new Object();
			wimpyConfigs560.wimpySwf="http://www.awal.com/Rave/rave.swf";
			wimpyConfigs560.wimpyApp="http://www.awal.com/Rave/wu2.xml";
			wimpyConfigs560.wimpyWidth="455";
			wimpyConfigs560.wimpyHeight="315";
			wimpyConfigs560.wimpyReg=" NGpla3F1JTNCJTI0TyU3RTklMjclM0FjZk0lNUMlN0IlNUNHZVBoazYyJTVD";
			wimpyConfigs560.wimpySkin="http://www.awal.com/Rave/WU/WU_Skin Machine/Layout from Profero.xml";
			wimpyConfigs560.autoAdvance="no";
			wimpyConfigs560.wimpyHTMLpageTitle="Yes! Effect Player";
			wimpyConfigs560.tptBkgd="yes";
			wimpyConfigs560.bkgdColor="#FFFFFF";
			makeWimpyPlayer(wimpyConfigs560, "musicPopupInner");
		}
		
		$("a#popupPlayer").unbind("click").click(function(){
			wimpy_stop();
			window.open( $(this).attr("href"), "popupWin", "width=600,height=400,scrollbars=no" );
			return false;
		});
		
		wuyes.setupDropdownNav();
		
		
		if(document.getElementById("effectCarousel")){
			wuyes.setupHomeEffects();
		}
		
		if(document.getElementById("photoEffectHolder")){
			wuyes.setupPhotoEffect();
		}
		
		$("#yesQuotes ul li a").mouseover(function(){
			$(this).toggleClass("current");
			var wId = $(this).parent().get(0).id;
			$("div#quote-"+wId).show();
		}).mouseout(function(){
			$(this).toggleClass("current");
			var wId = $(this).parent().get(0).id;
			$("div#quote-"+wId).hide();
		});
		
		
		
		
		
		
		
		if( $("#homeAuthorsSubnav") ){
			$("div#homeAuthorsSubnav *").css("visibility","visible");
			$("#homeAuthorsSubnav #next").click(function(){
				wuyes.nextauthor(1);
				this.blur();
				return false;
			});
			$("#homeAuthorsSubnav #prev").click(function(){
				wuyes.nextauthor(-1);
				this.blur();
				return false;
			});
		}
		
		if( $("#authorsnav") ){
			var els = $("#authorsnav ul li");
			for(var x=0; x<els.length; x++){
				if(els[x].className.indexOf("current") != -1){
					wuyes.currAuth = x;
					$("#authorsnav ul").css("background-position", "0 "+(x*-160)+"px");
				}
			}
			
			$("#authorsnav li a").mouseover(function(){
				var wEl = $("#authorsnav li a").index(this);
				if(wEl != wuyes.currAuth){
					$(this).addClass("donk");
				}
			}).mouseout(function(){
				$(this).removeClass("donk");
			});
		}
		
		$("#submitButton").click(function(){
			if ( $("#agreeterms").attr("checked") ) {
				
				//var storyGoto = "http://www.wuyeseffect.com/index.php/yes/say-yes/?storyredirect=true";
				var storyGoto = "http://www.wuyeseffect.com/index.php/say/";
				
				$("form#comment_form").attr("action",storyGoto);
				$("form#comment_form input[name='RET']").val(storyGoto);
				$("form#comment_form").submit();
			} else {
				alert("You must agree with the Privacy Policy and Terms & Conditions and Submission Policy");
			}
			return false;
			
			$("form#comment_form").submit(function(){
				alert("Thank you for your yes! story.");
				return false;
			});
		});
		
		
		
		wuyes.setupMusicArtists();
		
	},
	setupDropdownNav: function(){
		$("div#nav li#nav-choose a").unbind("click").click(function(){
			this.blur();
			$("div#dropdownNav").fadeIn("1000");
			return false;
		});
		$("div#dropdownNav li#dd-close a").unbind("click").click(function(){
			this.blur();
			$("div#dropdownNav").fadeOut("1000");
			return false;
		});
	},
	setupHomeEffects: function(){
		wuyes.currHomeEffect = 1;
		var numEffects = $("div#effectCarousel div.effectCarouselDiv").length;
		$("div#effectCarousel div.effectCarouselDiv a.prevEffect").unbind("click").click(function(){
			this.blur();
			wuyes.rotateHomeEffects(-1);
			return false;
		});
		$("div#effectCarousel div.effectCarouselDiv a.nextEffect").unbind("click").click(function(){
			this.blur();
			wuyes.rotateHomeEffects(1);
			return false;
		});
		
		var ofStr = (wuyes.isSpanish) ? " de " : " of ";
		$("div#effectCarousel div.effectCarouselDiv div.counter").each(function(i){
			$(this).text((i+1) + ofStr + numEffects);
		});
		
		$("div#effectCarousel div.effectCarouselDiv").hide();
		$("div#effectCarousel div.effectCarouselDiv:eq("+(wuyes.currHomeEffect-1)+")").show();
	},
	rotateHomeEffects: function(dir){
		var effects = $("div#effectCarousel div.effectCarouselDiv");
		var fadeSpeed = 250;
		
		var newHomeEffect = wuyes.currHomeEffect + dir;
		if(newHomeEffect > effects.length){
			newHomeEffect = 1;
		}
		if(newHomeEffect < 1){
			newHomeEffect = effects.length;
		}
		
		$(effects[wuyes.currHomeEffect-1]).fadeOut(fadeSpeed/2, function(){
			$(effects[newHomeEffect-1]).fadeIn(fadeSpeed);
		});
		
		wuyes.currHomeEffect = newHomeEffect;
	},
	setupMusicArtists: function(){
		if(document.getElementById("musicArtistsList")){
			$("div#musicArtistsList ul li").wrapInner('<a href="#"></a>');
			$("div#musicArtistsList ul li a").unbind("click").click(function(){
				if(!wuyes.artistFading){
					wuyes.artistFading = true;
					wuyes.selectMusicArtist( $(this) );
				}		
				this.blur();
				return false;
			});
			
			$("div#musicArtistsList ul li a:first").click();
		}
	},
	selectMusicArtist: function(wLink){
		$("div#musicArtistsList ul li").removeClass("current");
		$(wLink).parents("li").addClass("current");
		var wArtist = $(wLink).parents("li").attr("id");
		if( $("div.artistDetail.current").length > 0){
			$("div.artistDetail.current").fadeOut(300, function(){
				$("div.artistDetail.current").removeClass("current");
				$("div#artist-"+wArtist).addClass("current").fadeIn(500, function(){
					wuyes.artistFading = false;
				});
			});
		} else {
			$("div#artist-"+wArtist).addClass("current").fadeIn(500, function(){
				wuyes.artistFading = false;
			});
		}
	},
	setupPhotoEffect: function(){
		$("#photoEffectHolder").flash(
			{
				src: 		"http://portal.awal.com/yeseffect/wu_photofilter.swf",
				width: 		560,
				height: 	465,
				wmode: 		"transparent"
			},
			{
				version: 	9
			}
		);
	}
}






















