$(document).ready(function(){
	//DROPDOWN MENU INIT
	if(typeof ddsmoothmenu != 'undefined')
	ddsmoothmenu.init({
		mainmenuid: "mainMenu", //menu DIV id
		orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v"
		classname: 'ddsmoothmenu', //class added to menu's outer DIV
		//customtheme: ["#1c5a80", "#18374a"],
		contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
	})
	
	// PRETTY PHOTO INIT
	if(typeof $.prettyPhoto != 'undefined')
		$("a[rel^='prettyPhoto']").prettyPhoto();
	
	// SHOW/HIDE FOOTER ACTIONS
	/*
	$('#showHide').click(function(){	
		if ($("#footerActions").is(":hidden")) {
			$(this).css('background-position','0 0');
			$("#footerActions").slideDown("slow");
			
			} else {
			$(this).css('background-position','0 -16px') 
			$("#footerActions").hide();
			$("#footerActions").slideUp("slow");
			}
		return false;			   
	});*/		
	
	// TOP SEARCH 
	$('#s').focus(function() {
			//$(this).animate({width: "215"}, 300 );	
			$(this).val('');
			$(this).attr("class",this.className.replace(/default/gi,''));
	});
	
	/*
	$('#s').blur(function() {
			//$(this).animate({width: "100"}, 300 );
			$(this).val('symbol or name');
			$(this).attr("class",this.className + ' default');
	});*/
	
	
	// QUICK CONTACT
	/*
	$('#quickName').val('your name');
	$('#quickEmail').val('your email');
	$('#quickComment').val('your message');
	
	$('#quickName').focus(function() {
			$(this).val('');	
	});
	
	$('#quickEmail').focus(function() {
			$(this).val('');	
	});
	
	$('#quickComment').focus(function() {
			$(this).val('');	
	});
	*/
	
	//SHARE LINKS
	/*
	$('#shareLinks a.share').click(function() {
			if ($("#shareLinks #icons").is(":hidden")) {
			$('#shareLinks').animate({width: "625"}, 500 );
			$('#shareLinks #icons').fadeIn();
			$(this).text('[-] Share & Bookmark');
			return false;
			}else {
			$('#shareLinks').animate({width: "130"}, 500 );
			$('#shareLinks #icons').fadeOut();
			$(this).text('[+] Share & Bookmark');
			return false;	
			}
	});
	*/
	
	if(typeof $.fn.countable != 'undefined')
	$("#comment").countable({
		threshold: .5,
		appendMethod: "appendTo",
		target: $(".character-counter"),
		startOpacity: 1,
		maxLength: 500,
		positiveCopy: " ({n} characters left)",
		negativeCopy: " ({n} characters over the limit)"
		//fadeDuration: 0
		//defaultText: "Enter message"
	})
	
	//LEFT SIDEBAR MENU
	/*
	if( typeof $('#leaderboard-menu div').hoverIntent != 'undefined' ) {
		$('#leaderboard-menu div > ul').each(function(index) {
		    //if no active classes
		    if ( $(this).children('.active').length < 1) {
			    $(this).hide();
			    $(this).children('h3:first span:first').toggleClass('open');
			}
		 });
		
		var config = {    
		     over: function() {
				if ($(this).children('ul').is(":hidden") ) {
					$(this).children('ul').slideDown("slow",
							function() { //callback on complete
								$(this).prev().children('span:first').toggleClass('open');
						   	}
					);
				}
			 }, // function = onMouseOver callback (REQUIRED)    
		     timeout: 500, // number = milliseconds delay before onMouseOut    
		     out: function() {
				if ( $(this).children('ul').is(":visible") &&
				     $(this).children('ul:first').children('.active').length < 1 ) {
					$(this).children('ul').slideUp("slow",
							function() { //callback on complete
								$(this).prev().children('span:first').toggleClass('open');
						   	}
					);
				}
			 } // function = onMouseOut callback (REQUIRED)    
		};
		
		$("#leaderboard-menu div").hoverIntent( config );
	}*/
	
	//DASH MENU DROPDOWN
	if( typeof $('#dash-menu td').hoverIntent != 'undefined' ) {
		$('#dash-menu td > ul').each(function(index) {
		    $(this).hide();
		 });
		
		var config = {    
		     over: function() {
				if ($(this).children('ul').is(":hidden") ) {
					$(this).children('ul').slideDown("slow");
				}
			 }, // function = onMouseOver callback (REQUIRED)    
		     timeout: 500, // number = milliseconds delay before onMouseOut    
		     out: function() {
				if ( $(this).children('ul').is(":visible") ) {
					$(this).children('ul').slideUp("fast");
				}
			 } // function = onMouseOut callback (REQUIRED)    
		};
		
		$("#dash-menu td").hoverIntent( config );
	}
	
	//JQUERY UI CLASSES
	// Datepicker
	$(".datepicker").datepicker({inline: true, dateFormat: 'mm/dd/yy'});
	//Radioset
	$(".radioset").buttonset();
	//Combo Box
	$(".combobox" ).combobox();
	$(".button").button();
	
	//file upload
	if(typeof $.fn.filestyle != 'undefined')
	$("input[type=file]").filestyle({ 
	    fileButtonClass : "fileButton",
	    width : 273
	});
	$("input[class=file]").attr('readonly', true);
	$("input[class=file]").attr('title', $("input[type=file]").attr('title'));
	
	//TOOLTIPS by TIPSY
	if(typeof $.fn.tipsy != 'undefined')
	$('[title]').not(".dialogMarker").tipsy({gravity: $.fn.tipsy.autoNS});
	
	//Top Iframe
	$("iframe[name=ic_ga_track ]").height(0);
	
	var vouching = function(event) {
		var _id = event.target.id;
		var dir = _id.substring(0, _id.indexOf("-"));
		_id = _id.substring(_id.indexOf("-")+1);
		if(dir == "login") {
			modalDialog("vouch-login");
			return false;
		}
		$.ajax({url: event.target.href,
			dataType:'json',
			data: {id: _id, dir: dir},
			cache:false,
    		success: function(data){
    			if(data.success == 'true') {
    				var o = $("#"+event.target.id+"-count");
    				o.html(parseInt(o.html())+1);
    				if(data.update == 'true') {
    					dir = (dir == "up" ? "down":"up");
    					o = $("#" + dir + "-" + _id +"-count");
    					o.html(parseInt(o.html())-1);
    				}
    			} else {
    				if(data.self == "true")
    					modalDialog("vouch-self");
    			}
    		},
    		error : function(XMLHttpRequest, textStatus, errorThrown) {
    			console.debug(textStatus)
    		}
    	});
		
		return false;
	};
	$('.thumbsUp').click(vouching);
	$('.thumbsDown').click(vouching);
	$('#embed_btn').click(function() {modalDialog("embed_show"); return false;});
    
    $("#customDateCombo").combobox({selected:function(combo,selected){
    	var val = selected.item.value;
    	if(val == -1) {
    		$("#customDateDialog").dialog(
    			{ width: 350, resizable:false, modal:true,
	    		buttons: { "Ok": function() {
	    			document.location = $("#customDateUrl").val() + "?fromDate="
	        			+ $("#customDateStart").val()
	        			+ "&toDate=" + $("#customDateEnd").val();
	    		}, 
	    		"Cancel": function() { $(this).dialog("close")} }});
    	} else {
    		document.location = val;
    	}
    }});
    if(typeof Highcharts != 'undefined')
    Highcharts.setOptions({
        colors: ['#64E572', '#ED561B', '#058DC7', '#50B432','#DDDF00', '#24CBE5', '#FF9655', '#FFF263', '#6AF9C4']
    });
    
    /* PLANS CHART */

    var planRowClasses = $('#plans #items li');

    $('#plans li' ).hover(
       function () {
	       if( $(this).attr('class').indexOf('action') < 0 ) {
	    	   var clazz = $(this).attr('class').replace(/alt/i, '').replace(/ /i,'');
	    	   $('#plans li.' + clazz ).addClass('rowHighlight');
	    	   $(this).append( $('#plans li.' + clazz + ' .description') );
	    	   $('#plans li.' + clazz + ' .description').show();
	       }
       }, 
       function () {
         $('#plans li').removeClass('rowHighlight');
         $('#plans li .description').hide();
       }
    );


    $('#platinum ul, #silver ul, #gold ul, #free ul').each( function() {
    	$(this).children('li').each( function(i) {
    		$(this).addClass( planRowClasses[i].className );
    	});
    });
});
<!-- end document ready -->

function modalDialog(id) {
	$("#"+id).dialog({
		width:400,
		modal: true,
		buttons: {
			Ok: function() {
				$( this ).dialog( "close" );
			}
		}
	});
}

Number.prototype.formatMoney = function(c, d, t){
  var n = this, c = isNaN(c = Math.abs(c)) ? 2 : c, d = d == undefined ? "," : d, t = t == undefined ? "." : t, s = n < 0 ? "-" : "", i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
  return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
};


