function Global()
{
	this.init = function(){
		this.slide();
		this.helpMeChoose();
		this.testimonials();
		this.slideshow();
		this.updateViaForm();
		this.cleditor();
		this.ga();
		this.tooltip();
		
		var menu = new Menu();
		menu.init(); //enable dropdown menu
	}
	this.ga = function(){
		$('.eventrack').click(
		 function () { 
			var ID = $(this).attr('id');
			var text = $(this).text();
			try{
			_gaq.push(['_trackEvent', ID, 'Click', text]);
			}catch (err) {

			}
		 });
	}
	this.cleditor = function(){
		if($("#editPage").length != 0){
		 $("#editPage").cleditor({
	          width:        800, // width not including margins, borders or padding
	          height:       800, // height not including margins, borders or padding
	          controls:     // controls to add to the toolbar
	                        "bold italic underline strikethrough subscript superscript | font size " +
	                        "style | color highlight removeformat | bullets numbering | outdent " +
	                        "indent | alignleft center alignright justify | undo redo | " +
	                        "rule image link unlink | cut copy paste pastetext | print source",
	          colors:       // colors in the color popup
	                        "FFF FCC FC9 FF9 FFC 9F9 9FF CFF CCF FCF " +
	                        "CCC F66 F96 FF6 FF3 6F9 3FF 6FF 99F F9F " +
	                        "BBB F00 F90 FC6 FF0 3F3 6CC 3CF 66C C6C " +
	                        "999 C00 F60 FC3 FC0 3C0 0CC 36F 63F C3C " +
	                        "666 900 C60 C93 990 090 399 33F 60C 939 " +
	                        "333 600 930 963 660 060 366 009 339 636 " +
	                        "000 300 630 633 330 030 033 006 309 303",    
	          fonts:        // font names in the font popup
	                        "Arial,Arial Black,Comic Sans MS,Courier New,Narrow,Garamond," +
	                        "Georgia,Impact,Sans Serif,Serif,Tahoma,Trebuchet MS,Verdana",
	          sizes:        // sizes in the font size popup
	                        "1,2,3,4,5,6,7",
	          styles:       // styles in the style popup
	                        [["Paragraph", "<p>"], ["Header 1", "<h1>"], ["Header 2", "<h2>"],
	                        ["Header 3", "<h3>"],  ["Header 4","<h4>"],  ["Header 5","<h5>"],
	                        ["Header 6","<h6>"]],
	          useCSS:       false, // use CSS to style HTML when possible (not supported in ie)
	          docType:      // Document type contained within the editor
	                        '<!DOCTYPE HTML>',
	          docCSSFile:   // CSS file used to style the document contained within the editor
	                        "", 
	          bodyStyle:    // style to assign to document body contained within the editor
	                        "margin:4px; font:10pt Arial,Verdana; cursor:text"
	        });
		 
		 
			 var applicationPath = $('#applicationPath').html();
			 $.get(applicationPath + "application/views/" + $('#FolderUpdateFile').val() + "/" + $('#FileUpdateFile').val() + '.phtml', function(data){				 
				 $('#editPage').val(data);
				 $("#editPage").cleditor()[0].updateFrame(); 
				});
		 }
	}
	this.updateViaForm = function(){
		$('.UpdateViaForm').click(
				function(){
					$('#flashMessanger').show();
					var ajaxLoader = $('#ajaxLoader').html();
					$('#flashMessanger').html(ajaxLoader);
			    	 $('html, body').animate({scrollTop:0}, 'slow');
					var ID = $(this).attr('id');
					var FormID = '#' + ID + 'Trigger'; 
					var applicationPath = $('#applicationPath').html();
					var Serialize = $(FormID).serialize();
					var applicationPath = $('#applicationPath').html();

				
					$.post(applicationPath + 'backend/ajax.php', Serialize,
							   function(data){
					if($('#callback').length == 0)
					{
						$('#flashMessanger').html(data);
					}else{
						$('#flashMessanger').hide();
						$('#ajaxCallback').html(data);
					}
					});
				}
		);
	}
	this.slide = function(){
		    $("#sideMenu").jFlow({
            slides: "#slides",
			controller: ".jFlowControl",
            width: "700px",
            height: "1000px"
        });
	}
	this.slideshow = function(){
		$('#slideshow').hover(
		function(){
			$('.slideControls').show();
		},
		function(){
			$('.slideControls').hide();
		});
		
		$('.slideControls').click(
			function(){
				$.post('backend/ajax.php', {formID: 'slideshow', direction: $(this).attr('id')}, function(data) 				{
					$('#slideshowContent').fadeOut("slow", function(){$('#slideshowContent').fadeIn().html(data)});
				});
			});
	}
	this.helpMeChoose = function(){
		$(".hlepMeChoose").click(
		  function () { 
		  	var getID = $(this).attr("id");
		  	
			if(getID != 'pets' && getID != 'athletes')
			{
				$("#ShippingOutsideUS").fadeOut('slow', 
				function(){
				$("#BloodPressureMeds").fadeIn('slow')
				});	
			}else if(getID == 'athletes'){
				$('.explain').hide();
				$('#athletes > div:last-child').show();
				$.fancybox.close();
				$.scrollTo('#athletes', 800);
				$('#athletes').addClass('selectYellowBg');
			}else{
				$("#BloodPressureMeds").fadeOut('slow', 
				function(){
				$("#ShippingOutsideUS").fadeIn('slow')
				});
			}
		  }
		  
		);

	$('.helpMeConfirm').click(
		function(){

			$('.explain').hide();
			
			var getConfirmID = $(this).attr('id');
			var product;
			
			switch(getConfirmID)
			{
			case 'BloodPressureMedsYes':
			  product = 'original';
			  break;
			case 'BloodPressureMedsNo':
			   product = '1500';
			  break;
			case 'ShippingOutsideUSYes':
			   product = 'originalPets';
			  break;
			case 'ShippingOutsideUSNo':
			   product = 'beef';
			  break;
			default:
			}
			
			$('.ourProductsBox').each(
				function(){
					$(this).removeClass('selectYellowBg');
					
				});

			
	
			$('#' + product + ' > div:last-child').show();
			$.fancybox.close();
			$.scrollTo('#' + product, 800);
			$('#' + product).addClass('selectYellowBg');
	});
	}
	this.testimonials = function(){
		$('#testimonials ul li').click(
			function(){
				var  getText = $(this).text();
				var applicationPath = $('#applicationPath').html();
				_gaq.push(['_trackEvent', 'Testimonials', 'Click', getText]);
				$.post(applicationPath + 'backend/ajax.php', {formID: 'testimonial', category: getText}, function(data) {
					$('#testimonial').html(data);
					pageTracker._trackEvent('Testimonial', 'Click', text);
				});
			});
		$('#testimonials ul li').hover(
		function(){
			$(this).addClass('testimonialsHover');
		},
		function(){
			$('#testimonials ul li').each(
			function(){
				$(this).removeClass('testimonialsHover');
			}
			)
		});
	}
	this.tooltip = function(){
		$('#testimonials ul li').CreateBubblePopup({
			position : 'top',
			align	 : 'center',
			innerHtml: 'Click to read another <br /> success story!',
			innerHtmlStyle: {color:'#FFFFFF', 'text-align':'center'},
			themeName: 	'all-black',
			themePath: 	'images/jquerybubblepopup-theme'
		});

	};
}
var global = new Global();

$(document).ready(function() {
	
	global.init();
});

