/* MeritBuilder Main Configuration */
$(document).ready(function(){


	$('ul.sf-menu').superfish(); 

	
	// Photo upload ajax
	$('#photoUpload').ajaxForm({         
		beforeSubmit: function() {
			$(".uploadStatus").empty().html('<img src="../images/loading_bar.gif" />'); 
		},
		success: function() { 
            $(".uploadStatus").show().html('Your photo has been upload'); 
        } 
    });



	// bind to the change event 
    $('.tgl').change(function() { 
		 // inside event callbacks 'this' is the DOM element so we first 
        // wrap it in a jQuery object and then invoke ajaxSubmit 
        $(this).parents('.toggleVisible').ajaxSubmit(); 
        // !!! Important !!! 
        // always return false to prevent standard browser submit and page navigation 
        return false; 
    });

	
	

	// toggleVisible form
	$('.toggleVisible').ajaxForm({         
		beforeSubmit: function() {
			$(".msg").empty().html('<img src="../images/loading_bar.gif" />'); 
		},
		success: function() { 
            $(".msg").show().html('Updated!'); 
        } 
    });



//Dasboard news rotater
//Show Banner
	$(".main_image .desc").show(); //Show Banner
	$(".main_image .block").animate({ opacity: 1.0 }, 1 ); //Set Opacity

	//Click and Hover events for thumbnail list
	$(".image_thumb ul li:first").addClass('active'); 
	$(".image_thumb ul li").click(function(){ 
		//Set Variables
		var imgAlt = $(this).find('img').attr("alt"); //Get Alt Tag of Image
		var imgTitle = $(this).find('a').attr("href"); //Get Main Image URL
		var imgDesc = $(this).find('.block').html(); 	//Get HTML of block
		var imgDescHeight = $(".main_image").find('.block').height();	//Calculate height of block	
		
		if ($(this).is(".active")) {  //If it's already active, then...
			return false; // Don't click through
		} else {
			//Animate the Teaser				
			$(".main_image .block").animate({ opacity: 0, marginBottom: -imgDescHeight }, 250 , function() {
				$(".main_image .block").html(imgDesc).animate({ opacity: 1.0,	marginBottom: "0" }, 250 );
				$(".main_image img").attr({ src: imgTitle , alt: imgAlt});
			});
		}
		
		$(".image_thumb ul li").removeClass('active'); //Remove class of 'active' on all lists
		$(this).addClass('active');  //add class of 'active' on this list only
		return false;
		
	}) .hover(function(){
		$(this).addClass('hover');
		}, function() {
		$(this).removeClass('hover');
	});
			
	//Toggle Teaser
	$("a.collapse").click(function(){
		$(".main_image .block").slideToggle();
		$("a.collapse").toggleClass("show");
	});
	

// reflection
$(".sticker img").reflect(height=".08");
$("#sticker-index .sticker img, #profile-show .sticker img").unreflect();


// WordClouds

$("#wordcloud").tagcloud({type:"list",sizemin:8});
$("#profileWordcloud").tagcloud({type:"list",sizemin:14});
$("#corpWordCloud").tagcloud({type:"list",sizemin:14});
$("#sentWordCloud").tagcloud({type:"list",sizemin:14});
$("#toWordCloud").tagcloud({type:"list",sizemin:14});



// /* IE only rounded corners */
  DD_roundies.addRule('.rounded', '10px');
  // DD_roundies.addRule('.merit', '5px');
  DD_roundies.addRule('#body-wrapper', '8px');




/* 	Spaces display switch */
	$("a.switch_thumb").toggle(function(){
		$(this).addClass("swap");
		$("ul.display").fadeOut("fast", function() {
			$(this).fadeIn("fast").addClass("thumb_view");
		});
	}, function () {
		$(this).removeClass("swap");
		$("ul.display").fadeOut("fast", function() {
			$(this).fadeIn("fast").removeClass("thumb_view");
		});
	}); 




// Dashboard updates btn
$(".updatesBtn").click(
	function() {
		$(this).parent().parent().find("div").toggle("fast"); 
	}
);
  
	
/* 	Quick Add Achievement */
$("#quickAddAchieve").hide();	
		
$("#quickAddAchieveBtn").click( // 
			function () {
				$("#quickAddAchieve").toggle("fast"); 
				$('#quickAddAchieveBtn').toggleClass("current"); 
				$('#quickSendMeritBtn').removeClass("current"); 
				$("#quickSendMerit").hide();	
				return false;
			}
		);	
		
		
/* 	Quick send merit */
$("#quickSendMerit").hide();	
		
$("#quickSendMeritBtn").click( // 
			function () {
				$("#quickSendMerit").toggle("fast"); 
				$('#quickSendMeritBtn').toggleClass("current"); 
				$('#quickAddAchieveBtn').removeClass("current"); 
				$("#quickAddAchieve").hide();	
				return false;
			}
		);	
	
	
	// $("#feature1").hide(); 
	$("#feature2").hide(); 
	$("#feature3").hide(); 

	$("#feature4").hide(); 


	$("#featureBtn1").click( // When a top menu item is clicked...
			function () {
				$("#feature1").fadeIn("fast"); // Slide down the clicked sub menu
				$("#feature").fadeOut("slow"); 				
				$("#feature2").fadeOut("slow"); 
				$("#feature3").fadeOut("slow"); 
				$("#feature4").fadeOut("slow"); 
				$(this).addClass("current");
				$(this).siblings().removeClass("current");
				return false;
			}
		);
		
		$("#featureBtn2").click( // When a top menu item is clicked...
			function () {
				$("#feature2").fadeIn("fast"); // Slide down the clicked sub menu
				$("#feature").fadeOut("slow"); 				
				$("#feature1").fadeOut("slow"); 
				$("#feature3").fadeOut("slow"); 
				$("#feature4").fadeOut("slow"); 
				$(this).addClass("current");
				$(this).siblings().removeClass("current");
				return false;
			}
		);
		
			$("#featureBtn3").click( // When a top menu item is clicked...
			function () {
				$("#feature3").fadeIn("fast"); // Slide down the clicked sub menu
				
				$("#feature").fadeOut("slow"); 				
				$("#feature1").fadeOut("slow"); 
				$("#feature2").fadeOut("slow"); 
				$("#feature4").fadeOut("slow"); 

				$(this).addClass("current");
				$(this).siblings().removeClass("current");

				return false;
			}
		);
		
			$("#featureBtn4").click( // When a top menu item is clicked...
			function () {
				$("#feature4").fadeIn("slow"); // Slide down the clicked sub menu
				$("#feature").fadeOut("slow"); 				
				$("#feature1").fadeOut("slow"); 
				$("#feature2").fadeOut("slow"); 
				$("#feature3").fadeOut("slow"); 

				$(this).addClass("current");
				$(this).siblings().removeClass("current");

				return false;
			}
		);

	
	
		$("#leaveFeedback").hide(); //Hide leaveFeedback

		$("#leaveFeedbackBtn").click( // When a top menu item is clicked...
				function () {
					$("#leaveFeedback").fadeIn("slow"); // Slide down the clicked sub menu
					return false;
				}
			);
			
			$("#cancelFeedbackBtn").click( // When a top menu item is clicked...
				function () {
					$("#leaveFeedback").fadeOut("slow"); // Slide down the clicked sub menu
					return false;
				}
			);
			
			
	
	
	
	$("#loginDiv").hide(); //Hide login top

	$("#loginButton").click( // When a top menu item is clicked...
			function () {
				$("#loginDiv").slideToggle("normal"); // Slide down the clicked sub menu
				$("#searchDiv").hide(); //Hide login top
				return false;
			}
		);
		
	$("#searchDiv").hide(); //Hide login top

	$("#searchButton").click( // When a top menu item is clicked...
			function () {
				$("#searchDiv").slideToggle("normal"); // Slide down the clicked sub menu
				$("#loginDiv").hide(); //Hide login top
				return false;
			}
		);

	
		
	//Products sliders

	$(".templateBrowser").easySlider({

		prevId: 'prevBtn',
		nextId: 'nextBtn' 

	});
	
	
	
	//Products sliders

	$("#productSection2").easySlider({

		prevId: 'prevBtn2',
		nextId: 'nextBtn2' 

	});
	
	$("#productSection3").easySlider({
/*
		auto: true,
		continuous: true 
		
*/		prevId: 'prevBtn3',
		nextId: 'nextBtn3'
	});

	$("#productSection4").easySlider({
/*
		auto: true,
		continuous: true 
		
*/		prevId: 'prevBtn4',
		nextId: 'nextBtn4'
	});	
	

	
	// Login box
	
	$(".signin").click(function(e) {
	                e.preventDefault();
	                $("fieldset#signin_menu").toggle();
	                $(".signin").toggleClass("menu-open");
	            });

	            $("fieldset#signin_menu").mouseup(function() {
	                return false
	            });
	
	            $(document).mouseup(function(e) {
	                if($(e.target).parent("a.signin").length==0) {
	                    $(".signin").removeClass("menu-open");
	                    $("fieldset#signin_menu").hide();
	                }
	            });
	
	
	
	
	
	// TOOLTIPS
	
	$('#forgot_username_link').tipsy({gravity: 'w'}); 
	
	

	//Sidebar Accordion Menu:
		
		$("#main-nav li ul").hide(); //Hide all sub menus
		$("#main-nav li a.current").parent().find("ul").slideToggle("slow"); // Slide down the current menu item's sub menu
		
		$("#main-nav li a.nav-top-item").click( // When a top menu item is clicked...
			function () {
				$(this).parent().siblings().find("ul").slideUp("normal"); // Slide up all sub menus except the one clicked
				$(this).next().slideToggle("normal"); // Slide down the clicked sub menu
					
				$("#main-nav li a.current").removeClass("current"); 
				$(this).addClass("current");	
				return false;
			}
		);
		
		$("#main-nav li a.no-submenu").click( // When a menu item with no sub menu is clicked...
			function () {
				window.location.href=(this.href); // Just open the link instead of a sub menu
				return false;
			}
		); 
		

		
		

    // Sidebar Accordion Menu Hover Effect:
		
		$("#main-nav li a.nav-top-item").hover(
			function () {
				$(this).animate({ paddingRight: "25px" }, 200);
			}, 
			function () {
				$(this).animate({ paddingRight: "15px" });
			}
		);
		
		
		

    //Minimize Content Box
		
		$(".content-box-header h3").css({ "cursor":"s-resize" }); // Give the h3 in Content Box Header a different cursor
		$(".content-box-header-toggled").next().hide(); // Hide the content of the header if it has the class "content-box-header-toggled"
		
		$(".content-box-header h3").click( // When the h3 is clicked...
			function () {
			  $(this).parent().parent().find(".content-box-content").toggle(); // Toggle the Content Box
			  $(this).parent().toggleClass("content-box-header-toggled"); // Give the Content Box Header a special class for styling and hiding
			  $(this).parent().find(".content-box-tabs").toggle(); // Toggle the tabs
			}
		);

    // Content box tabs:
		
		$('.content-box .content-box-content div.tab-content').hide(); // Hide the content divs
		$('.content-box-content div.default-tab').show(); // Show the div with class "default-tab"
		$('ul.content-box-tabs li a.default-tab').addClass('current'); // Set the class of the default tab link to "current"
		
		$('.content-box ul.content-box-tabs li a').click( //When a tab is clicked...
			function() { 
				$(this).parent().siblings().find("a").removeClass('current'); // Remove "current" class from all tabs
				$(this).addClass('current'); // Add class "current" to clicked tab
				var currentTab = $(this).attr('href'); // Set variable "currentTab" to the value of href of clicked tab
				$(currentTab).siblings().hide(); // Hide all content divs
				$(currentTab).show(); // Show the content div with the id equal to the id of clicked tab
				return false; 
			}
		);

    //Close button:
		
		$(".close").click(
			function () {
				$(this).parent().fadeTo(400, 0, function () { // Links with the class "close" will close parent
					$(this).slideUp(600);
				});
				return false;
			}
		);

    // Alternating table rows:
		
		$('tbody tr:even').addClass("alt-row"); // Add class "alt-row" to even table rows

    // Check all checkboxes when the one in a table head is checked:
		
		$('.check-all').click(
			function(){
				$(this).parent().parent().parent().parent().find("input[type='checkbox']").attr('checked', $(this).is(':checked'));   
			}
		)

    // Initialise Facebox Modal window:
		
		$('a[rel*=modal]').facebox(); // Applies modal window to any link with attribute rel="modal"

    // Initialise jQuery WYSIWYG:
		
		// $(".wysiwyg").wysiwyg();

});
  
  
  