$(document).ready(function(){ 
						
		/********** sub nav control - when click on sub page, accordion open/close ********/					
		var hash = $.url.attr("anchor");
		var page = $.url.attr("path");
		var page = page.replace(/\/+/g, ""); //just get the page name
		var prosuite_subpages = { "proscript" : 0, "prodoc" : 1, "procapture" : 2 };
		var consulting_subpages = { "about" : 0, "whatwedo" : 2, "howwedoit" : 3 };
		var training_subpages = { "custom" : 0, "smesolutions" : 1, "prosuite" : 2, "clienttestimonials" :3 };
		var smesolutions_subpages = { "sapbusinessone" : 0, "integration" : 1, "reporting" : 2, "consulting" : 3 };
	
		$('#accordion-smesolutions,  #accordion-consulting, #accordion-training').accordion({ 
			active: false,
			autoheight: false,
			collapsible: true,
			clearStyle: true						
		});		
		$('#accordion-prosuite').accordion({ 
			active: false,
			autoheight: false,
			collapsible: true,
			clearStyle: true,										   
			event: false 
		});
		
		expandIt();

		$("ul.subnav a").click(function(){			
			tmpHash = hash;								
			hash = $.url.setUrl($(this).attr("href")).attr("anchor");
			if(tmpHash != hash && hash != 'retail' && hash != 'manufacturing' && hash != 'distribution' ){
				expandIt();
				//hide all SME sub pages
				$(".module-smesolutions-retail").hide("slow");
				$(".module-smesolutions-manufacturing").hide("slow");
				$(".module-smesolutions-distribution").hide("slow");
			}
		});
		
		function expandIt(){
			if( hash != null ){		
				subpages = "";
				
				switch (page){
					case 'prosuite': 
						subpages = prosuite_subpages;
					break;
					case 'consulting':
						subpages = consulting_subpages;
					break;
					case 'training':
						subpages = training_subpages;						
					break;	
					case 'smesolutions':
						subpages = smesolutions_subpages;						
					break;	
					default: 
						subpages = prosuite_subpages;
				}				
			
				$( "#accordion-" + page ).accordion("activate", subpages[hash]);
				
				if( page == 'prosuite'){
					$(".module-proscript img.product, .module-prodoc img.product, .module-procapture img.product").animate({"opacity":1}, 1000);
				}
			}
			if( page == 'smesolutions' && hash == null ){				
				$(window).load(function() {
					$( "#accordion-" + page ).accordion("activate", 0);
				});
			}
		}
		/********** sub nav control - when click on sub page, accordion open/close ********/
		
		/**************** CTA handling (trial, add to cart and demo) *************/
		
	$(".bouncers a.icon-try, .bouncers a.icon-buy, .bouncers a.icon-demo")
			.mouseover(function(){
				$(this)
					.css("background-position", "0 -74px")
					.animate({backgroundPosition:"(0 -76px)"}, {duration:100})
					
				})
			.mouseout(function(){
				$(this)
					.css("background-position", "0 -228px")
				
				});
	$(".ctas-demo-bouncers a.cta-freetrial, .ctas-demo-bouncers a.cta-training, .ctas-demo-bouncers a.cta-buy, .ctas-demo-bouncers form.shopp input")
			.mouseenter(function(){
				$(this)
					.css("background-position", "0 -48px")	
					.animate({backgroundPosition:"(0 -51px)"}, {duration:100})
				})
			.mouseleave(function(){
				$(this)
					.css("background-position", "0 -176px")						
				})
			;
	
		/*************/
		
	/*********** handling agreement checkbox on shop page *************/
	$("#agree").click(function(){
		if( $('#agree').is(':checked') ){
			$('a#checkout').show('slow');
		}
		else{
			$('a#checkout').hide('slow');
		}
	});

	/*********** end handling agreement checkbox on shop page *************/
		var IE7 = (navigator.userAgent.toLowerCase().indexOf('msie 7') != -1);	
		/**************** product box animation within accordion - is for prosuite page *****************/
		$(".module-proscript a.icon-plus").click(function(){
			animateImageInAccordion("module-proscript");
			activateSingleAccordion("#accordion-prosuite", 0);
			$('html, body').delay(500).animate({scrollTop: $("#logo-proscript").offset().top}, 2000);
	//		$.scrollTo( '#logo-proscript', 800 );
		});
		$(".module-prodoc a.icon-plus").click(function(){																   
			animateImageInAccordion("module-prodoc");
			activateSingleAccordion("#accordion-prosuite", 1);	
			$height = 720;
			if( IE7 )
				$height=700;			
			$('html, body').delay(500).animate({scrollTop: $height}, 2000);
//			$.scrollTo( '#logo-prodoc', 800 );
		});
		
		$(".module-procapture a.icon-plus").click(function(){
			animateImageInAccordion("module-procapture");
			activateSingleAccordion("#accordion-prosuite", 2);					
			$height = 950;
			if( IE7 )
				$height=930;			
			$('html, body').delay(500).animate({scrollTop: $height}, 2000);
			
//			$('html').delay(1500).animate({scrollTop: '500px'}, 2000);
			//$.scrollTo( '#logo-procapture', 800 );
		});
		
		
		function activateSingleAccordion(sec, idx){
			$( sec ).accordion("activate", idx);
		}
		
		function animateImageInAccordion(module){
			var isOpen = false;
			var tmpSelectedAccordion = $("." + module).attr('class').split(" ");
			if( tmpSelectedAccordion.length == 2 ){
				isOpen = true;	
			}
			
			if( isOpen == false) { //is closed	
				
				$("." + module + " img.product").animate({"opacity":0}, 600);
			}
			else{
				$("." + module + " img.product").animate({"opacity":1}, 1000);
			}
		}
		/**************** product box animation within accordion *****************/
		
		/**************** accordion control on smesolutions page (SAP, Integration, Reporting & Consulting) *****************/
		
		$("a#logo-sapbusinessone,a#logo-reporting,a#logo-integration,a#logo-consulting, #accordion-sapbusinessone a.icon-plus, #accordion-integration a.icon-plus, #accordion-reporting a.icon-plus, #accordion-consulting a.icon-plus, .handle").click(function(){																
			$('.module-smesolutions-retail').hide("slow");	
			$('.module-smesolutions-manufacturing').hide("slow");
			$('.module-smesolutions-distribution').hide("slow");	
			
		});
		
		/**************** product box animation within accordion *****************/
		
		
		
		
		
	});
