/* Author: Len Dierickx

*/

// function pulse(cssClass, pulseSpeed) {
//     $(cssClass).animate({
//         opacity: 0.6
//     },
//     pulseSpeed,
//     function() {
//         $(cssClass).animate({
//             opacity: 1
//         },
//         pulseSpeed,
//         function() {
//             pulse(cssClass, pulseSpeed);
//         });
//     });
// };



$(document).ready(function() {
    
    $("#classes .full").attr('title','This class is fully booked');
    $("#classes .full").each(function(){
      fullybooked =  $(this).attr("href");
	  $( fullybooked ).parents("tr").css({'background':'rgba(255,0,0,.3)','color':'white'});
	  $( fullybooked ).parents("tr").find("td:first-child").append("<a class=\"waitinglist\" href=\"salsa-courses-info.html#waitinglist\">Get on the waitinglist</a>");	
      $( fullybooked + " strong").addClass('full');
      $( fullybooked + " span.availability a").remove();
    });
    $("#classes a:not(.full)").each(function(){
      openClass =  $(this).attr("href");
	  $( openClass ).parents("tr").find("td:first-child").append("<a class=\"subscribe\" href=\"salsa-courses-info.html#cesar\">How to Subscribe?</a>");	
    });
    $(".availability").not(".full").append("&nbsp;&nbsp;&nbsp;<a title=\"Back to the top\" href=\"#cesar\">Top "+String.fromCharCode(8593)+"</a>");
    // $(".availability").not(".full").append("&nbsp;&nbsp;&nbsp;<a title=\"Back to the top\" href=\"#cesar\">Top "+String.fromCharCode(8593)+"</a>")


    $("table#faq-salsa-dancing tr td").each(function(){
        currentIndex = "faq"+($(this).parent().prevAll().length+1);
        $(this).parent().attr("id",currentIndex)
    });
 
    $("table#faq-salsa-dancing tr:even").add("#salsa-articles tr:even").addClass("box-blue");
    $("table#faq-salsa-dancing tr:odd").add("#salsa-articles tr:odd").addClass("box-orange");
    
    $("table#faq-salsa-dancing tr:odd").add("#salsa-articles tr:odd").mouseover( function(){
        $(this).css("background-color","rgba(255,157,46,0.7)");
    }).mouseout(function(){ $(this).css("background-color","rgba(255,157,46,0.2)") }).click(function(){ window.location = $(this).find("a:eq(0)").attr("href");
    });
    $("table#faq-salsa-dancing tr:even").add("#salsa-articles tr:even").mouseover( function(){
        $(this).css("background-color","rgba(90,164,164,0.7)")
    }).mouseout(function(){ $(this).css("background-color","rgba(90,164,164,0.2)") }).click(function(){ window.location = $(this).find("a:eq(0)").attr("href");});

    var d = new Date();

    $("span.thisyear").text(d.getFullYear());
    if(jQuery().fancybox){
        $("a[rel*=fancyvideo]").fancybox({
                        'overlayColor'		: '#000',
        				'overlayOpacity'	: 0.9
                    });        
    }


     $(".hideandscroll").each(function(index){        
        m = $(this).parents("div:eq(0)").attr("id");    
        $(this).prev().append("<small><a class=\"more\" href=\"#"+m+"\">Read more &rarr;</a></small>");
        
        $(this).find("p:last-child").append("<small><a class=\"less\" href=\"#"+$(this).parents("div:eq(0)").attr("id")+"\">&larr; Read less</a></small>");
        
        
     });
      
                
    //$(".hideandscroll").prev().append("<small><a class=\"more\" href=\"#"+$(".hideandscroll").parent().attr("id")+"\">Read more &rarr;</a></small>");
//    $(".hideandscroll p:last-child").append("<small><a class=\"less\" href=\"#"+$(".hideandscroll").parent().attr("id")+"\">&larr; Read less</a></small>");
    
    
    
   
    $(".more").click(function(){ 
        console.log( $(this).attr('href'), "Soemthing went wrong" );
        
        $( $(this).attr('href') + " .hideandscroll").toggle();
        $(this).toggle();
        return false;
    });
    $(".less").click(function(){
        console.log( $(this).attr('href'), "Soemthing went wrong" );
        $( $(this).attr('href') + " .hideandscroll").toggle();
        $( $(this).attr('href') ).find("a.more").toggle();
    });
    

    $(".polaroids li").each(function(){
        randomnumber=Math.floor(Math.random()*4)
        switch(randomnumber){
            case 1: 
                $(this).addClass("right8");
                break;
            case 2: 
                $(this).addClass("left4");
                break;
            case 3: 
                $(this).addClass("left10");
                break;
            case 0: 
                $(this).addClass("right3");
                break;
        }
    });

    // $("#signup input#email").focus(function(){
    //     $(this).val(" ");
    // })
    // $("#signup form").submit(function(){
    //     var reg = /\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i;
    //     var address = $(this).find("#email").val();
    //         if(reg.test(address) == false) {alert('Invalid Email Address');return false}
    //         else{return true}
    //     return false;
    // });

	var toc = toc || [];
	$("table#salsa-articles tr").each(function(){    
		toc.push( new Array( $(this).find("td:first-child a").text() , $(this).find("td:first-child a").attr("href") ) );
		// alert( $(this).find("td:first-child a").text() );
	});
  	$("#toc-articles").append(function(){
		t = '<ol>';
		$.each(toc, function(index, value){
				t += "<li><a href=\""+value[1]+"\">"+value[0]+"</a></li>";
		});
		return t+"</ol>";
	});
	$("a.breadCrumbTitle").text( document.title );
	// $("#header").append("<div id=\"stamp\" style=\"position:absolute; width:220px;height:220px; top:"+ ( $("#header").height()-200 ) +"px; left:"+ ( $("#header .yui-gc").position().left -100 ) +"px;\"><span style=\"visibility:hidden\">Formerly known as César and Louise</span></div>");

		$("a.fancyCal").fancybox({
            'titleShow'         : false,
            'overlayColor'		: '#000',
			'overlayOpacity'	: 0.9
        });

});

