var BASEURL = 'http://' + window.location.hostname + '/';
if(BASEURL == SECURE) {
	BASEURL = GLHT;
}
var selectedHt = 46;
var productsSelHt = 52;

var timeout    = 300;
var closetimer = 0;
var ddMenu = 0;
var subDdMenu = 0;

var productsDropContents = '<span id="certs"><img class="smOMRI" src="' +  BASEURL + 'images/OMRIsm.png"/><br /><span id="tiny">These products are OMRI listed.</span></span><span class="menuGroups menuGroup1"><a href="' +  BASEURL + 'bioStimulant.php" class="menuLink">Bio-Stimulant</a><br><a href="' +  BASEURL + 'liquidEnergy.php" class="menuLink">Liquid Energy</a><br><a href="' +  BASEURL + 'glassandmirror.php" class="menuLink">Glass &amp; Mirror Answer&reg;</a><br><a href="' +  BASEURL + 'cleanngreen.php" class="menuLink">Clean \'N\' Green Answer&reg;</a></span><span class="menuGroups menuGroup2"><a href="' +  BASEURL + 'heavycleaner.php" class="menuLink">Heavy Cleaner Answer&reg;</a><br><a href="' +  BASEURL + 'odorcontrol.php" class="menuLink">Odor Control Answer&reg;</a><br><a href="' +  BASEURL + 'vitaminzyme.php" class="menuLink">Vita-Min-Zyme</a></span>';

var infoDropContents = '<a class="menuLink" href="' +  BASEURL + 'bioLogic1.php"><span class="floatL infoMenu info1"><img src="' +  BASEURL + 'images/biologicBuMenu.png" border="0"><br><span class="menuText">Bio Logic</span></span></a><a class="menuLink" href="' +  BASEURL + 'testimonials.php"><span class="floatL infoMenu info2"><img border="0" src="' +  BASEURL + 'images/testimonialsBuMenu.png"/><br /><span class="menuText">Testimonials</span></span></a><a class="menuLink" href="' +  BASEURL + 'benefits.php"><span class="floatL infoMenu info3"><img src="' +  BASEURL + 'images/benefitsBuMenu.png" border="0"><br><span class="menuText">Benefits</span></span></a><a class="menuLink" href="' +  BASEURL + 'faq.php"><span class="floatL infoMenu info4"><img src="' +  BASEURL + 'images/faqBuMenu.png" border="0"><br><span class="menuText">FAQs</span></span></a><a class="menuLink" href="' +  BASEURL + 'videos.php"><span class="floatL infoMenu info5"><img src="' +  BASEURL + 'images/videosBuMenu.png" border="0"><br><span class="menuText">Videos</span></span></a><a class="menuLink" href="' +  BASEURL + 'links.php"><span class="floatL infoMenu info6"><img src="' +  BASEURL + 'images/linksBuMenu.png" border="0"><br><span class="menuText">Links</span></span></a><a class="menuLink" href="' +  BASEURL + 'info.php#downloads"><span class="floatL infoMenu info7"><img src="' +  BASEURL + 'images/downloadsBuMenu.png" border="0"><br><span class="menuText">Downloads</span></span></a>'; 

/*var infoSubDropBioLogicContents = '<div class="bioLogicSubDrop"><a href="' +  BASEURL + 'bioLogic1.php" class="link"><img src="' +  BASEURL + 'images/biologicBu.png" border="0"><br>Bio Logic</a><br><br><div class="subDocs bioLogicSubDocs"><a href="' +  BASEURL + 'bioLogic1.php" class="subDocsLink">BioLogic 1<br></a><a href="' +  BASEURL + 'bioLogic2.php" class="subDocsLink">BioLogic 2<br></a><a href="' +  BASEURL + 'bioLogic3.php" class="subDocsLink">BioLogic 3<br></a><a href="' +  BASEURL + 'bioLogic4.php" class="subDocsLink">BioLogic 4<br></a><a href="' +  BASEURL + 'bioLogic5.php" class="subDocsLink">BioLogic 5<br></a><a href="' +  BASEURL + 'bioLogic6.php" class="subDocsLink">BioLogic 6<br></a><a href="' +  BASEURL + 'bioLogic7.php" class="subDocsLink">BioLogic 7<br></a></div></div><!--end of bioLogicSubDrop-->';*/

$.fn.image = function(src, f){
	return this.each(function(){
		var i = new Image();
		i.src = src;
		i.onload = f;
		this.appendChild(i);
	});
}

/*function getSessionId(session) {
	alert(session);
	$.post("http://secure.biologicalservices.com/store.php", { sid: session } );
}*/
function ddClose() {
	if(ddMenu) {
		$('#dropMenu')
			.stop()
			.animate({height: 0}, 200)
			.hide()
			.removeClass('infoDropMenu productsDropMenu')
			.children()
				.hide();
		$('.subDrop').stop().hide();
		
	}
}

/*function subDdClose() {
	if(subDdMenu) {
		$('.subDrop').stop().empty().hide();
	}
}*/

function ddCancelTimer() {
	if(closetimer) {
		window.clearTimeout(closetimer);
      	closetimer = null;
	}
}

/*function subDdCancelTimer() {
	if(subDdMenu) {
		window.clearTimeout(subDdMenu);
      	subDdMenu = null;
	}
}*/

function ddTimer() {
	closetimer = window.setTimeout(ddClose, timeout);
}

/*function subDdTimer() {
	subDdMenu = window.setTimeout(subDdClose, timeout);
}*/

function returnDocument() {
	var file_name = document.location.href;
	if(file_name == BASEURL || file_name == "http://greenlawnandhome.com/" || file_name == "https://greenlawnandhome.com/" || file_name == "https://www.greenlawnandhome.com/") {
		file_name = BASEURL + 'index.php';
	}
	var end = (file_name.indexOf("?") == -1) ? file_name.length : file_name.indexOf("?");
	return file_name.substring(file_name.lastIndexOf("/")+1, end);
}

var page = returnDocument();

function fromLeft(elem) {
	var position = elem.position();
	var fromLeftEdge = position.left;
	elem.parents().each(function() {
		var parentPos = $(this).position();					  
		fromLeftEdge += parentPos.left
	});
	return fromLeftEdge;
}

/*function jugHover() {
	ddCancelTimer();
		
	$('.infoMenu').hover(function(event) {
		if($(this).hasClass('info1')) {
			subDropMenuOver('info1');
		} else {
			subDdTimer();
		}
	}, function(event) {
		var bioLogicLeft = fromLeft($('.info1'));
		if(event.clientX < bioLogicLeft || event.clientX > ( bioLogicLeft + $('.info1').width() ) ) {
			subDropMenuOut();
		}
	});
}*/

function navOver(navId) {
	ddCancelTimer();
	ddClose();
	if(navId == "Products" || navId == "Info") {
		$('#dropMenu').empty().append('<div class="subDrop"></div>');
		if(navId == "Products") {
			var dropContents = productsDropContents;
			$('#dropMenu').removeClass('infoDropMenu').addClass('productsDropMenu');
			var leftEdge = $('#' + navId).css('left').slice(0, -2);
		} else if(navId == "Info") {
			var dropContents = infoDropContents;
			$('#dropMenu').removeClass('productsDropMenu').addClass('infoDropMenu');
			var leftEdge = $('#' + navId).css('right').slice(0, -2);
		}
		ddMenu = $('#dropMenu')
			.stop()
			.animate({height: 112}, 'fast', function() {
				$(this)
					.show()
					.append(dropContents)
					.css({overflow: 'visible'});
			});
		dropTabControl();
		$('.subDrop').hide();
		$('#dropMenu').hover(function() {
			ddCancelTimer();
			dropTabControl();
			//jugHover();
		}, function(event) {
			
			if(event.relatedTarget.id != 'Products' && event.relatedTarget.id != 'Info') {
				ddTimer();
			}
			tabControl('none');
		});
	}
}

function navOut(navId) {
	tabControl('none')
		ddTimer();
}

/*function subDropMenuOver(subMenu) {
	subDdCancelTimer();
	$('#dropMenu').css({overflow: 'visible'});
	$('.subDrop').stop().empty();
	if(subMenu == 'info1') {
		$('.subDrop').stop().append(infoSubDropBioLogicContents);
	}
		
	var left = $('.' + subMenu)[0].offsetLeft - 6;
	$('.subDrop')
		.stop()
		.show()
		.css({left: left, height: 275});
}

function subDropMenuOut() {
	subDdTimer()
}*/

function dropTabControl() {
	if($('.productsDropMenu').is(':visible')) {
		$('#Products').css({backgroundImage: 'url(' + BASEURL + 'images/tabOverLong.png)', height: productsSelHt});
	} else if($('.infoDropMenu').is(':visible')) {
		$('#Info').css({backgroundImage: 'url(' + BASEURL + 'images/tabOverLong.png)', height: productsSelHt});
	}
}

function tabControl(currentTab){
	var periodIndex = page.indexOf('.');
	var tabStrFromPageName = page.substring(0,1).toUpperCase() + page.substring(1, periodIndex);
	var currentPage = tabStrFromPageName;
	if(currentPage == "BioLogic1" || currentPage == "BioLogic2" || currentPage == "BioLogic3" || currentPage == "BioLogic4" || currentPage == "BioLogic5" || currentPage == "BioLogic6" || currentPage == "BioLogic7" || currentPage == "Benefits" || currentPage == "Faq" || currentPage == "Testimonials" || currentPage == "Links") {
		currentPage = "Info";
	}
	if(currentPage == "Bionliven" || currentPage == "Carbon" || currentPage == "Glassandmirror" || currentPage == "Cleanngreen" || currentPage == "Heavycleaner" || currentPage == "Odorcontrol" || currentPage == "Vitaminzyme" || currentPage == "Fulviccream") {
		currentPage = "Products";
	}
	if(currentPage == "Index") {
		currentPage = "Home";
	}
	
	$('div.navTab').css({backgroundImage: 'url(' + BASEURL + 'images/tab.png)', height: selectedHt});
	$('#' + currentPage).css({backgroundImage: 'url(' + BASEURL + 'images/tabOver.png)', height: selectedHt});
	if(currentTab != 'none') {
		$('#' + currentTab).css({backgroundImage: 'url(' + BASEURL + 'images/tabOver.png)', height: selectedHt});
	}
	
}

$(function() {
		   //alert(window.location.href);
	$('#main, #header, #rightSide2, .navTab, #footer, #content, #hmTitle, .top-label, .content-area, .storeContent, .round').corners("12px transparent");
	
	if(page == 'bioLogic2.php') {
		$('.blLeftBox1').width(260);
	}

	if(page == 'bioLogic3.php') {
		$('.blLeftBox1').css({backgroundColor: '#FFFFFF'});
		$('.bioRight').width(325);
	}

	if(page == 'bioLogic4.php') {
		$('.blLeftBox1').width(300);
		$('.blLeftBox1').css({border: 'none'});
		$('.bioRight').width(300);
	}	
	
	if(page == 'bioLogic5.php' || page =='bioLogic6.php') {
		$('.blLeftBox1').width(475);
		$('.blLeftBox1').css({border: 'none', marginRight: '0'});
		$('.bioRight').width(300);
	
	}	
	
	if(page == 'bioLogic7.php') {
		$('.blLeftBox1').width(225);
		$('.blLeftBox1').css({border: 'none'});
		$('.bioRight').width(400);
		$('.titleL').css({padding: '0'});
	}	
	
	if(page == 'application.php') {
		$('#rightSide').width(375);
	} else if(page == 'testimonials.php') {
		$('#rightSide').width(550);
	} else if(page == 'faq.php' || page == 'faq.php#' ) {
		$('#rightSide').width(550);
	} else if(page == 'login.php') {
		$('#leftSide').css({'left': 50, 'top': 30, 'width': 326});
		$('#rightSide').css({'right': 50, 'top': 30, 'width': 326});
	}
	
	if(page == 'gallery.php') {
		jQuery(document).ready(function($) {
			// We only want these styles applied when javascript is enabled
			$('div.navigation').css({'width' : '275px', 'float' : 'left'});
			$('div.content').css('display', 'block');
		
			// Initially set opacity on thumbs and add
			// additional styling for hover effect on thumbs
			var onMouseOutOpacity = 0.67;
			$('#thumbs ul.thumbs li').opacityrollover({
				mouseOutOpacity:   onMouseOutOpacity,
				mouseOverOpacity:  1.0,
				fadeSpeed:         'fast',
				exemptionSelector: '.selected'
			});
			
			// Initialize Advanced Galleriffic Gallery
			var gallery = $('#thumbs').galleriffic({
				delay:                     2500,
				numThumbs:                 12,
				preloadAhead:              10,
				enableTopPager:            false,
				enableBottomPager:         true,
				maxPagesToShow:            7,
				imageContainerSel:         '#slideshow',
				controlsContainerSel:      '#controls',
				captionContainerSel:       '#caption',
				loadingContainerSel:       '#loading',
				renderSSControls:          false,
				renderNavControls:         true,
				playLinkText:              '',
				pauseLinkText:             '',
				prevLinkText:              '&lsaquo; Previous',
				nextLinkText:              'Next &rsaquo;',
				nextPageLinkText:          'Next Page &rsaquo;',
				prevPageLinkText:          '&lsaquo; Prev Page',
				enableHistory:             false,
				autoStart:                 false,
				syncTransitions:           true,
				defaultTransitionDuration: 900,
				onSlideChange:             function(prevIndex, nextIndex) {
					// 'this' refers to the gallery, which is an extension of $('#thumbs')
					this.find('ul.thumbs').children()
						.eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
						.eq(nextIndex).fadeTo('fast', 1.0);
				},
				onPageTransitionOut:       function(callback) {
					this.fadeTo('fast', 0.0, callback);
				},
				onPageTransitionIn:        function() {
					this.fadeTo('fast', 1.0);
				}
			});
			resize();
		});
	} else if(page == 'bioStimulant.php' || page == 'liquidEnergy.php') {
		jQuery.ajax({
			type: "POST",
			url: "getComboPrice.php",
			dataType: "html",
			success: function(response){
				var comboPrice = response;
				$('.comboProPrice').append('Combo Price: $' + comboPrice);
			}
		});
	}
});

$(function() {
	//alert("hello");
	//$('a[rel=lightbox]').lightBox()
	/*$('img').ready(function(){
		//resize();
	})*/
	
	/*tabControl('none');
	var nav = $('div.navTab');
	nav.height(selectedHt);
	$('#dropMenu').hide();
	$('.subDrop').hide();
	
	nav.hover(function() {
		if ($.browser.msie) {
			$('#dropMenu').children().css({display: 'none'});
		}
		var whichTab = $(this).attr('id');
		//alert(whichTab);
		$('#' + whichTab).css({backgroundImage: 'url(' + BASEURL + 'images/tabOver.png)', height: selectedHt});
		tabControl(whichTab);
		navOver(whichTab);
	} , function() {
		if ($.browser.msie) {
			 if(!($('.productsDropMenu').is(':visible)')) && !($('.infoDropMenu').is(':visible'))) {
				$('#dropMenu').children().css({display: 'none'});
			 }
		}
		var whichTab = $(this).attr('id');
		$('#' + whichTab).css({backgroundImage: 'url(' + BASEURL + 'images/tab.png)', height: selectedHt});
		navOut(whichTab);
	});
	$('.bioLogicNav').jqDock({align: 'middle', labels: 'bc', duration: 100, size: 40});*/
});