// JavaScript (ECMAScript) by Armando Emanuel Roggio, the Elder for D&B Supply, www.dbsuppply.com.
// Have a suggestion for improving this code? Please email aroggio@dbsupply.com or aeroggio@gmail.com
// Please feel free to use our code, but if you do, please think positively about D&B Supply,
// and please follow us on Twitter, @dbsupply, and on Facebook, http://www.facebook.com/dbsupply.
// God bless.


baseLocation();


//This function normalizes the base URL across sandbox and production servers
function baseLocation(){
	var curUrl = String(document.location);
	baseLocUrl = curUrl.replace(/index.php\S*/, '');
}


//Cufon Font Replacement

Cufon.replace('#locations', {
	fontFamily: 'ChunkFiveRegular', 
	textShadow: '#000 1px 1px 3px'
	});
Cufon.replace('#prod-title', {
	fontFamily: 'ChunkFiveRegular',
	textShadow: '#404040 1px 1px 1px'
	}); 
Cufon.replace('#prod-facts, #prod-img-more, #account-page-title, #review-form h2', {
	fontFamily: 'ChunkFiveRegular',
	textShadow: '#000 1px 1px 1px'
	}); 
Cufon.replace('.current_customer h2, .new_customer h2, .create-account-page-title, .account-create-wrap .legend, .single-page-wrapper h1, .single-page-wrapper h2, .single-page-wrapper h3, #review-form h3, .flyers h3, .single-page-wrapper h4, .product-name a', {
	fontFamily: 'ChunkFiveRegular'
	}); 
Cufon.replace('#head-content-links, #ft-merc-blog h3, #ft-merc-blog h2, .header .links', {
	fontFamily: 'Lao UI',
	textShadow: '#a6a6a6 1px 0 1px'
	}); 
Cufon.replace('#ft-merc-video h6', {
	fontFamily: 'Lao UI',
	textShadow: '#000000 1px 0 1px'
	});	
Cufon.replace('#footer-links, #checkoutSteps #opc-login button em', {
	fontFamily: 'Lao UI'
	});
Cufon.replace('.blog-dateline, .blog-details, .blog-comment-form label, .left-category-block, #checkoutSteps .validation-advice', {
	fontFamily: 'Lao UI',
	textShadow: '#c5c5c5 0 0 1px'
	});
Cufon.replace('.field-label', {
	fontFamily: 'Lucida Handwriting',
	textShadow: '#c5c5c5 0 0 1px'
	});
Cufon.replace('#nav .level0 > a, #nav .level1 > a, .block-title, #compare-actions, .acc-left .block-content ul li', {
	fontFamily: 'Carnivalee Freakshow'
	}); 
Cufon.replace('.cart .cart-collaterals .totals table, #checkoutSteps #opc-login button, #checkoutSteps #co-billing-form button, #checkoutSteps #opc-shipping button, #checkoutSteps #co-shipping-method-form button, #checkoutSteps #opc-payment #checkout-step-payment button, #checkoutSteps #opc-review #review-buttons-container button, #post-checkout-continue', {
	fontFamily: 'ChunkFiveRegular'
	}); 
	
	

/*
Cufon.replace('#locations', {
	fontFamily: 'ChunkFiveRegular', 
	textShadow: '#000 1px 1px 3px'
	}); 
Cufon.replace('#head-content-links, #ft-merc-blog h3, #ft-merc-blog h2', {
	fontFamily: 'Lao UI',
	textShadow: '#a6a6a6 1px 0 1px'
	}); 
Cufon.replace('#ft-merc-video h6', {
	fontFamily: 'Lao UI',
	textShadow: '#000000 1px 0 1px'
	});
Cufon.replace('.header .links', {
	fontFamily: 'Lao UI',
	textShadow: '#a6a6a6 1px 0 1px'
	});
Cufon.replace('#footer-links', {
	fontFamily: 'Lao UI'
	});
Cufon.replace('.field-label', {
	fontFamily: 'Lucida Handwriting',
	textShadow: '#c5c5c5 0 0 1px'
	});
Cufon.replace('#nav', {
	fontFamily: 'Carnivalee Freakshow'
	}); 
Cufon.replace('.block-title', {
	fontFamily: 'Carnivalee Freakshow'
	}); 
Cufon.replace('#compare-actions', {
	fontFamily: 'Carnivalee Freakshow'
	}); 
Cufon.replace('#prod-title', {
	fontFamily: 'ChunkFiveRegular',
	textShadow: '#404040 1px 1px 1px'
	}); 
Cufon.replace('#prod-facts', {
	fontFamily: 'ChunkFiveRegular',
	textShadow: '#000 1px 1px 1px'
	}); 
Cufon.replace('#prod-img-more', {
	fontFamily: 'ChunkFiveRegular',
	textShadow: '#000 1px 1px 1px'
	}); 
Cufon.replace('#account-page-title, #review-form h2', {
	fontFamily: 'ChunkFiveRegular',
	textShadow: '#000 1px 1px 1px'
	}); 
Cufon.replace('.new_customer h2', {fontFamily: 'ChunkFiveRegular'}); 
Cufon.replace('.current_customer h2', {
	fontFamily: 'ChunkFiveRegular'
	}); 
Cufon.replace('.create-account-page-title', {
	fontFamily: 'ChunkFiveRegular'
	}); 
Cufon.replace('.account-create-wrap .legend', {
	fontFamily: 'ChunkFiveRegular'
	}); 
Cufon.replace('.acc-left .block-content ul li', {
	fontFamily: 'Carnivalee Freakshow'
	}); 
Cufon.replace('.single-page-wrapper h1', {
	fontFamily: 'ChunkFiveRegular'
	}); 
Cufon.replace('.single-page-wrapper h2', {
	fontFamily: 'ChunkFiveRegular'
	}); 
Cufon.replace('.single-page-wrapper h3, #review-form h3, .flyers h3', {
	fontFamily: 'ChunkFiveRegular'
	}); 
Cufon.replace('.single-page-wrapper h4', {
	fontFamily: 'ChunkFiveRegular'
	}); 
Cufon.replace('.blog-dateline', {
	fontFamily: 'Lao UI',
	textShadow: '#c5c5c5 0 0 1px'
	});
Cufon.replace('.blog-details', {
	fontFamily: 'Lao UI',
	textShadow: '#c5c5c5 0 0 1px'
	});
Cufon.replace('.blog-comment-form label', {
	fontFamily: 'Lao UI',
	textShadow: '#c5c5c5 0 0 1px'
	});
Cufon.replace('.left-category-block', {
	fontFamily: 'Lao UI',
	textShadow: '#c5c5c5 0 0 1px'
	});

	*/
	


//EVENT LISTENERS

//window.onload = new function(){handleLoad();}
document.observe("dom:loaded", function() {
	handleLoad();
});


document.onclick = handleClick;
document.onkeypress = handleKeyPress;
document.onmouseover = handleHover;
//document.onmouseout = handleMouseOut;


function handleLoad(){
	//setTimeout('locAllCarousel()', 2000);	
	//setTimeout('heroCarousel()', 2000);
	initScroll();
	locusPelagus();
	if(String(document.location) == baseLocUrl + 'index.php'){
		heroCrossFade(0);
	}

	if(String(document.location) == baseLocUrl + 'index.php/'){
                heroCrossFade(0);
        }
	
	if(String(document.location) == baseLocUrl){
		heroCrossFade(0);
	}
	
	

}

function handleClick(e){
	if(!e) var e = window.event; // compensate for browser differences
	var target = e.target || e.srcElement;
	//compensate for how some browsers manage offsetParent after DOM manipulation
	var offPapa = target.offsetParent || document.getElementsByTagName('BODY');
	var offPapaPN = offPapa.parentNode || document.getElementsByTagName('BODY');
	var doublePapa = target.parentNode.parentNode || document.getElementsByTagName('BODY');
	var triplePapa = target.parentNode.parentNode.parentNode || document.getElementsByTagName('BODY');
	var quadPapa = target.parentNode.parentNode.parentNode.parentNode || document.getElementsByTagName('BODY');
	

	switch(target.id){
		case "customer-loc-sub" :
		stopDefault(e);
		findClosestStoreOne();
		break;
		case "map-modal-close-a" :
		stopDefault(e);
		locationModalEradicator();
		break;
		case "map-modal-close-img" :
		stopDefault(e);
		locationModalEradicator();
		break;
		case "mapBack" :
		locationModalEradicator();
		break;
		case "printDirAnchor" :
		stopDefault(e);
		printSetUp();
		break;
		case "lPVclose-img" :
		lPVEradicator();
		break;
		case "lPVback" :
		lPVEradicator();
		break;
		case "contact-link" :
		stopDefault(e);
		contactScroll();
		break;
		case "loc-left-arrow-link" :
		locAllCarousel('left')
		break;
		case "loc-right-arrow-link" :
		locAllCarousel('right')
		break;
		case "hero-control-right-img" :
		heroCntrlRght();
		break;
		case "hero-control-left-img" :
		heroCntrlLft();
		break;
		case "close-coupon-modal" :
		destroyCoupon();
		break;
		case "curtainModal" :
		destroyCoupon();
		break;
		case "view-flyer" :
		pageTurner(e)
		stopDefault(e);
		break;
		case "flyer-image" :
		pageTurner(e)
		stopDefault(e);
		break;
		case "close-flyer-modal" :
		destroyFlyer();
		break;
		case "flyerModal" :
		destroyFlyer();
		break;
	}
		if(heroClick){
			stopDefault(e);
			heroClick = false;	
		}

	if(target.href == document.location + 'index.php/locations' || offPapaPN.href == document.location + 'index.php/locations' || triplePapa.href == document.location + 'index.php/locations' || offPapaPN.href == 'http://199.204.138.106/index.php/locations' || triplePapa.href == 'http://199.204.138.106/index.php/locations' || target.href == 'http://199.204.138.106/index.php/locations' ){
		stopDefault(e);
		locScroll();
	}
	
	
	if(doublePapa.id == "contact-link" || target.className == "contact-link"){
		stopDefault(e);
		contactScroll();	
	}
	
	if(target.parentNode.className == "video-side-title"){changeVideo(target.parentNode.id)}
	if(offPapa.className == "video-side-title"){changeVideo(target.offsetParent.id)}
	if(quadPapa.className == "video-side-title"){changeVideo(target.parentNode.parentNode.parentNode.parentNode.id)}
	if(triplePapa.className == "video-side-title"){changeVideo(target.parentNode.parentNode.parentNode.id)}
	if(offPapaPN.className == "video-side-title"){changeVideo(target.offsetParent.parentNode.id)}
	if(target.className == "coupon-img-button-p"){printCoupon(target)}
	if(target.className == "coupon-img-button-e"){emailCoupon(target)}
	if(target.className == "coupon-img-button-t"){textCoupon(target)}
	if(target.parentNode.className == "hh-control-item" || doublePapa.className == "hh-control-item"){stopDefault(e);heroCntrlFade(target);};
	if(target.className == "pod-player"){addPodPlayer(target);}
	if(target.parentNode.parentNode.parentNode.className == "grid_3 top-locations"){lPVmodal(e);} /*WORKING ON LOCATIONS*/
	
	
	switch(target.className){
		case "grid_2 locus-pelagus-vid-a" :
		stopDefault(e);
		lPVmodal(e);
		break;	
		case "video-side-title" :
		changeVideo(target.id);
		break;
		case "contest-coupon" :
		contestCoupon(target);
		break;
		case "fourhffa-card-image" :
		fourhffaCardPrint(target);
		break;
	}
	

}

function handleKeyPress(e){
		var code;
		if(!e) var e = window.event;
		if (e.keyCode) code = e.keyCode;
		else if (e.which) code = e.which;
		if (e.currentTarget) aim = e.currentTarget.activeElement.id; // compensate for browser differences
		else if (e.srcElement.id) aim = e.srcElement.id;
										
		if(code == 13 && aim == "customer-loc"){
			stopDefault(e);
			findClosestStoreOne();
		}
		

}

function handleHover(e){
	if(!e) var e = window.event; // compensate for browser differences
	var target = e.target || e.srcElement;
	switch(target.id){
		case "map-modal-close-img" :
		locModalCloseFlip();
		break;
		case "1_locus" :
		locusPelagusCent(43.649281,-116.657349);
		break;
		case "2_locus" :
		locusPelagusCent(43.641640,-116.657555);
		break;
		case "3_locus" :
		locusPelagusCent(45.340927,-118.044998);
		break;
		case "4_locus" :
		locusPelagusCent(44.024746,-116.992348);
		break;
		case "5_locus" :
		locusPelagusCent(42.562824,-114.422058);
		break;
		case "6_locus" :
		locusPelagusCent(43.116421,-115.779617);
		break;
		case "7_locus" :
		locusPelagusCent(43.618797,-116.371735);
		break;
		case "8_locus" :
		locusPelagusCent(42.714928,-114.518433);
		break;
		case "9_locus" :
		locusPelagusCent(43.666088,-116.279251);
		break;
		case "10_locus" :
		locusPelagusCent(43.536587,-116.572029);
		break;
		case "11_locus" :
		locusPelagusCent(44.795990,-117.851830);
		break;
		case "12_locus" :
		locusPelagusCent(45.658768,-118.808868);
		break;
		case "lPVclose-img" :
		lPVflip();
		break;
		//case "locations" :
		//locAllCarousel();
		////locAllCarPause();
		//break;
	}
	
		
	/*if(target.className == 'hh-slider' || target.parentNode.className == 'hh-slider' || target.offsetParent && target.offsetParent.id == 'home-hero-slider'){
		 clearTimeout(heroCarTimer);
		 if(!heroInDrag){
		 	heroInDrag = new Draggable('home-hero-slider', {constraint: 'horizontal'});			
		 }
		 heroClick = true;
	}*/
}	

/*function handleMouseOut(e){
	if(!e) var e = window.event; // compensate for browser differences
	var target = e.target || e.srcElement;
	switch(target.id){
		case "map-modal-close-img" :
		locModalCloseFlip();
		break;
		case "lPVclose-img" :
		lPVflip();
		break;
		//case "locations" :
		//locAllCarReStart(e);
		//break;

	}
	

	if(target.className == 'hh-slider' || target.parentNode.className == 'hh-slider' || target.offsetParent && target.offsetParent.id == 'home-hero-slider' || target.id == 'home-hero-slider'){			        heroCarRestart(e);
	}
	
}	

function handleMouseUp(e){
	if(heroClick){
		stopDefault(e);
		heroClick = false;	
	}
}
*/

function stopDefault(e) {
    if (e.preventDefault) {
        e.preventDefault();
    } else {
        e.returnValue = false;
    }
    return false;
}



/* Determine if the Navigator is IE, and if so extract the version */

function isIe(){
	var rv = -1;
	var ua = navigator.userAgent;
	var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
	if(re.exec(ua) !=null){
		rv = parseFloat( RegExp.$1 );	
	}
	return rv;
}



//FLAGS

var gMapsRuns = false; //this flag keeps track of whether or not the Google Maps API is initialized
var heroClick = false; //this flag is for the hero slider, I needed a way to prevent a default click, when it was released.
var heroInDrag = false;


//LOCATIONS -- this section works with the Google Maps API to manipulate store location data
//Collect user input from a web form with the id of find-store-all, text field id of customer-loc
//wherein the submit button has an id of customer-loc-sub

var geocoder, directions, map, cusDestination;

function initialize(){
	geocoder = new google.maps.Geocoder();
	gMapsRuns = true;
	findClosestStoreTwo();	
}


//this function came from a Google Map API example. Thank you Google.
function parseXml(str) {
   if (window.ActiveXObject) {
      var doc = new ActiveXObject('Microsoft.XMLDOM');
      doc.loadXML(str);
      return doc;
     } else if (window.DOMParser) {
        return (new DOMParser).parseFromString(str, 'text/xml');
      }
   }


function findClosestStoreOne(){
	cusLoc = document.getElementById('customer-loc'); //get the form text field

	if(!cusLoc.value){
		var mes = 'Please enter an address or zip code';
		cusLoc.value = mes;
		cusLoc.placeholder = mes;
		//if a blank form was submitted change the value and placeholder
	}
	
	if(!gMapsRuns){
		  var script = document.createElement("script");
		  script.src = "http://maps.google.com/maps/api/js?sensor=false&callback=initialize";
		  document.body.appendChild(script);
		  //this adds the script tag and URL for the Google Maps API to the page	
		  gMapsRuns = true;
	}
	else{
		findClosestStoreTwo();	
	}
}

function findClosestStoreTwo(){
		geocoder.geocode( {'address': cusLoc.value}, function(results, status){
			if(status == google.maps.GeocoderStatus.OK) {
				var latitude = results[0].geometry.location.lat();
				var longitude = results[0].geometry.location.lng();
				//this finds and stores the customer's location as latitude and longitude
				cusDestination = new google.maps.LatLng(latitude, longitude);	
				findClosestStoreThree(baseLocUrl + 'js/dutch/find-nearby-store.php?latitude=' + latitude + '&longitude=' + longitude, function(data){findClosestStoreFour(data)});
			}
			else{
				cusLoc.value= 'error geocoding';	
			}
		});	
}

function findClosestStoreThree(url, callback){
	var request = window.ActiveXObject ?
		new ActiveXObject('Microsoft.XMLHTTP') :
		new XMLHttpRequest;
	request.onreadystatechange = function() {
  		if (request.readyState == 4) {
     	
     	callback(request.responseText, request.status);
   		}
 	};

 request.open('GET', url, true);
 request.send(null);
//this calls a PHP file which runs the Haversine formula across the array of store locations
//in order to find the closest store
}


function findClosestStoreFour(data){
	var mapBack = document.createElement('div');
	mapBack.id = 'mapBack';
	document.getElementById('wrapper').appendChild(mapBack);
	var mapSpot = document.createElement('div');
	mapSpot.id = 'mapSpot';
	document.getElementById('wrapper').appendChild(mapSpot);
	var mapImages = document.createElement('div');
	mapImages.id = 'mapFrame';
	mapSpot.appendChild(mapImages);
	var actualMap = document.createElement('div');
	actualMap.id = 'Google-Map';
	mapImages.appendChild(actualMap);	
	
	
	var xml = parseXml(data); 
	var eachStore = xml.documentElement.getElementsByTagName('store');
	map = new google.maps.Map(document.getElementById('Google-Map'), {
        center: new google.maps.LatLng(parseFloat(eachStore[0].getAttribute('latitude')), parseFloat(eachStore[0].getAttribute('longitude'))),
        zoom: 13,
        mapTypeId: 'roadmap',
		mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU}
    });
	for(var i = 0; i < eachStore.length; i++){
		var store = eachStore[i].getAttribute('store_name');
		var street = eachStore[i].getAttribute('street');
		var city = eachStore[i].getAttribute('city');
		var state = eachStore[i].getAttribute('state');
		var zip = eachStore[i].getAttribute('zip');
		var phone = eachStore[i].getAttribute('phone');
		var distance = parseFloat(eachStore[i].getAttribute('distance'));
		distance = distance.toFixed(2);
		var latitude = parseFloat(eachStore[i].getAttribute('latitude'));
		var longitude = parseFloat(eachStore[i].getAttribute('longitude'));
		if(i < 3){						
			var storeInfo = document.createElement('div');
			if(i ==0){
				store = store.split(' ').join(''); //remove spaces from the store name
				storeInfo.id = 'store-info' + [i];
				storeInfo.innerHTML = '<ul><li><img src="' + baseLocUrl + 'skin/frontend/dutch/dutch/images/license-plate-' + store + '-v0.png" alt="' + store + '" id="map-modal-plate" /></li><li>' + street + '</li><li>' + city +  ', '  + state +  ' '  + zip + '</li><li>' + phone + '</li></ul>';
			}
			else{
				storeInfo.id = 'store-info' + [i];
				storeInfo.innerHTML = '<ul><li><h3>' + store + '</h3></li><li>' + street + '</li><li>' + city +  ', '  + state +  ' '  + zip + '</li><li>' + phone + '</li><li>About ' + distance + ' miles</li></ul>';
			}
		mapSpot.appendChild(storeInfo);				
		}
		if(i == 0){
			var directionsSection = document.createElement('div');
			directionsSection.id = 'store-directions';
			directionsSection.innerHTML = '<h6> Directions...</h6><span id="printDir"><a href=" " id="printDirAnchor">Print Directions</a></span><span id="moreDir"><div id="moreDir-slider" ></div><div id="moreDir-handle" class="moreDir-handle"></div><img id="moreDir-slide-mess" src="' + baseLocUrl + 'skin/frontend/dutch/dutch/images/map-modal-scroll-me-balloon.png" alt="scroll me" /></span>';
			document.getElementById('store-info0').appendChild(directionsSection);
			directions = new google.maps.DirectionsService();
			var showDirections = new google.maps.DirectionsRenderer();
			var findRoute = {origin: cusDestination, destination: new google.maps.LatLng(latitude, longitude), travelMode: google.maps.DirectionsTravelMode.DRIVING, unitSystem: google.maps.DirectionsUnitSystem.IMPERIAL};
			directions.route(findRoute, function(response, status){
			if(status == google.maps.DirectionsStatus.OK){				
				showDirections.setPanel(document.getElementById('store-directions'));
				showDirections.setDirections(response);
			
			
			}
		});
		}
		
		createMarker(latitude, longitude, store, phone);
		
	}
		locationModalMaker('mapSpot');
		locationModalCloseMaker();
		adjustDirHeight();
		
		
		var nearByText = document.createElement('div');//adds some text not generated in the API
		nearByText.id ='near-by-text';
		nearByText.innerHTML = 'Also Nearby:';
		document.getElementById('mapSpot').appendChild(nearByText);

		
}

function createMarker(lat, long, store, phone){
	var markerMes = "<h3 id='map-marker-head'>" + store + "</h3><span id='map-marker-phone'>" + phone + "</span>";
	var markerPos = new google.maps.LatLng(lat,long);
	var marker = new google.maps.Marker({
		map: map, 
		position: markerPos,
		icon: baseLocUrl + '/skin/frontend/dutch/dutch/images/gmaps-marker-v082310.png'
	});
}


function locationModalMaker(id){
	var modalEle = document.getElementById(id);
	var modalWide = modalEle.offsetWidth;
	if (window.innerWidth) var wide = window.innerWidth;
	else if (document.body.clientWidth) var wide = document.body.clientWidth;
	var wCalc = (wide-modalWide)/2;
	if(!modalEle.style.left){
		modalEle.style.left = wCalc + 'px';
	}
	else{
		modalEle.style.left = wCalc + 'px';	
	}

}

function locationModalCloseMaker(){
	var mapModalClose = document.createElement('div');
	mapModalClose.id = 'map-modal-close';
	mapModalClose.innerHTML = '<a id="map-modal-close-a" href=" "><img id="map-modal-close-img" src="' + baseLocUrl + '/skin/frontend/dutch/dutch/images/map-modal-close-btn.png" alt="close"/></a>';
	document.getElementById('mapSpot').appendChild(mapModalClose);	
}

function locModalCloseFlip(){
	var mapModalClose = document.getElementById('map-modal-close-img');
	if(/btn.png/.test(mapModalClose.src)){
		mapModalClose.src = baseLocUrl + '/skin/frontend/dutch/dutch/images/map-modal-close-btn-wh.png';
	}
	else{
		mapModalClose.src = baseLocUrl + '/skin/frontend/dutch/dutch/images/map-modal-close-btn.png';
	}
}

function locationModalEradicator(){
	var deathRow = new Array('mapBack', 'mapSpot', 'jsts');
	for(var i = 0; i< deathRow.length; i++){
		var parent = document.getElementById(deathRow[i]).parentNode;
		var inmate = document.getElementById(deathRow[i]);
		parent.removeChild(inmate);
	}
}

function adjustDirHeight(){
	//adjust the height of the div holding the directions
	var dirDiv = document.getElementById('store-directions');
	var dirTrs = dirDiv.getElementsByTagName('tr');
	var dirPrint = document.getElementById('printDir');
	var dirMore = document.getElementById('moreDir');
	var dirSlideMess = document.getElementById('moreDir-slide-mess');
	var dirSumHt = dirDiv.getElementsByTagName('div');
	var dirSlideTarg = dirDiv.getElementsByTagName('table');
	
	//locate a couple of divs by class name
	for(var i =0; i < dirSumHt.length; i++){
		if(dirSumHt[i].className == 'adp-summary') dirSumHt = dirSumHt[i].offsetHeight;		
	}
	for(var i = 0; i < dirSlideTarg.length; i++){
		if(dirSlideTarg[i].className == 'adp-directions'){
			dirSlideTarg[i].parentNode.style.position = 'relative'; //fix an IE6 & IE7 bug while I am here
			dirSlideTarg[i].parentNode.style.height = dirTrs[1].offsetHeight + dirTrs[2].offsetHeight + 25 + 'px';//fix an IE6 & IE7 bug while I am here
			dirSlideTarg = dirSlideTarg[i];
		}
	}
	
	if(dirTrs.length < 1){
		var adjustDirHeightTimer = 	setTimeout(function(){adjustDirHeight()}, 5);
		return false;
	}
	else{
		clearTimeout(adjustDirHeightTimer);	
		var heightOne = dirTrs[1].offsetHeight;
		var heightTwo = dirTrs[2].offsetHeight;
		if((heightOne + heightTwo) < 250){
			dirDiv.style.height = heightOne + heightTwo + dirSumHt + 25 + 'px';
			var slideMessTimer = setInterval(function(){
				//dirSlideMess.setStyle({display: 'none'});
				dirSlideMess.style.display = 'none';
				clearInterval(slideMessTimer);
			}, 1800);
			if(dirTrs.length >= 4){
				//dirMore.setStyle({display: 'block'});
				dirMore.style.display = 'block';
				new Control.Slider(document.getElementById('moreDir-handle'), document.getElementById('moreDir-slider'), {
					axis: 'vertical',
					sliderValue: 5,
					increment: 1,
					maximum: heightOne + heightTwo,
					range: $R(-(dirSlideTarg.offsetHeight - dirSumHt - 20),0),
					onSlide: function(value){
						//dirSlideTarg.setStyle({top: value + 'px'});
						dirSlideTarg.style.top = value + 'px';
					},
					onChange: function(value){
						//dirSlideTarg.setStyle({top: value + 'px'});
						dirSlideTarg.style.top = value + 'px';
					}
				});	
			}
		}
		else{
			dirDiv.style.height = heightOne + dirSumHt + 20 + 'px';	
			var slideMessTimer = setInterval(function(){
				dirSlideMess.setStyle({display: 'none'});
				clearInterval(slideMessTimer);
				}, 1800);
				if(dirTrs.length >= 3){
					dirMore.setStyle({display: 'block'});
				new Control.Slider(document.getElementById('moreDir-handle'), document.getElementById('moreDir-slider'), {
					axis: 'vertical',
					sliderValue: 5,
					increment: 1,
					maximum: heightOne + heightTwo,
					range: $R(-(dirSlideTarg.offsetHeight - dirSumHt - 20),0),
					onSlide: function(value){
						dirSlideTarg.setStyle({top: value + 'px'});
					},
					onChange: function(value){
						dirSlideTarg.setStyle({top: value + 'px'});
					}
				});	
			}
				
			
		}
		
		
		
	}
	
	
	dirPrint.style.top = (parseInt(dirDiv.style.height) + 320) + 'px';
	var dirSlideMessCalc = document.getElementById('moreDir-handle').offsetTop - (dirSlideMess.offsetHeight * .8) - 5;
	dirSlideMess.style.top = dirSlideMessCalc + 'px';
	
}

function printSetUp(){
	var dirContent;
	var dirDiv = document.getElementById('store-directions');
	var dirDivTable = dirDiv.getElementsByTagName('table');
	for(var i = 0; i < dirDivTable.length; i++){
		if(dirDivTable[i].className == 'adp-directions'){
			dirContent = dirDivTable[i].parentNode.innerHTML;
		}
	}
	
	var printPageHead = '<html><head><title>D&amp;B Supply: Print Directions</title></head><body><h3><a href="javascript:window.print()">Print These Directions</a></h3>' + dirContent + '</body></html>';
	var printWindow = window.open('', '');
	printWindow.document.write(printPageHead);
	
		
}



//Locus Pelagus Map

function locusPelagus(){
	
	var locus = document.getElementById('locus-pelagus-map');
	if(locus != null){
		var script = document.createElement("script");
		script.src = "http://maps.google.com/maps/api/js?sensor=false&callback=locusPelagus2";
		document.body.appendChild(script);
		//this adds the script tag and URL for the Google Maps API to the page	
	}
}

function locusPelagus2(){
		
		locusMap = new google.maps.Map(document.getElementById('locus-pelagus-map'), {
       	  center: new google.maps.LatLng(43.649281, -116.657349),
      	  zoom: 15,
          mapTypeId: 'roadmap',
		  mapTypeControl: false
    	});	
		
		var marker = new google.maps.Marker({
		  map: locusMap, 
		  position: new google.maps.LatLng(43.649281, -116.657349),
		  icon: baseLocUrl + '/skin/frontend/dutch/dutch/images/gmaps-marker-v082310.png'
		});
		findClosestStoreThree(baseLocUrl + '/js/dutch/find-nearby-store.php?latitude=43.649281&longitude=-116.657349', function(data){locusPelagus3(data)});		
}

function locusPelagus3(data){
	
	var xml = parseXml(data); 
	var eachStore = xml.documentElement.getElementsByTagName('store');
	
	for(var i = 0; i < eachStore.length; i++){
		var latitude = parseFloat(eachStore[i].getAttribute('latitude'));
		var longitude = parseFloat(eachStore[i].getAttribute('longitude'));
		var markerPos = new google.maps.LatLng(latitude, longitude);
		var marker = new google.maps.Marker({
		map: locusMap, 
		position: markerPos,
		icon: baseLocUrl + '/skin/frontend/dutch/dutch/images/gmaps-marker-v082310.png'
	});
	}
		
}

function locusPelagusCent(lat,lng){
	locusMap.panTo(new google.maps.LatLng(lat,lng));
}



// Locus Pelagus Video Playback Modal Window Maker 

function lPVmodal(e){
	if(!e) var e = window.event; // compensate for browser differences
	var target = e.target || e.srcElement;
	if(target.tagName == "CANVAS") target = target.parentNode.parentNode.parentNode;
	var lPVparent = document.getElementById('wrapper');
	var lPVoverlay = document.createElement('div');
	lPVoverlay.id = 'lPVback';
	lPVparent.appendChild(lPVoverlay);
	var lPVbox = document.createElement('div');
	lPVbox.id = 'lPVbox';
	lPVparent.appendChild(lPVbox);
	locationModalMaker(lPVbox.id);
	Effect.ScrollTo('locations', {duration: '.5', offset: -40});
	var lPVclose = document.createElement('div');
	lPVclose.id = 'lPVclose';
	lPVclose.innerHTML = '<a id="lPVclose" href=" "><img id="lPVclose-img" src="' + baseLocUrl + '/skin/frontend/dutch/dutch/images/map-modal-close-btn.png" alt="close"/></a>';
	document.getElementById('lPVbox').appendChild(lPVclose);			
	var lPVplayer = document.createElement('div');
	lPVplayer.id = 'locus-pelagus-player';
	lPVplayer.innerHTML = '<object width="445" height="272"><param name="movie" value="http://www.youtube.com/v/' + target.id +'?fs=1&amp;hl=en_US&amp;autoplay=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/' +  target.id + '?fs=1&amp;hl=en_US&amp;autoplay=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="448" height="277"></embed></object>'
	lPVbox.appendChild(lPVplayer);	
}

function lPVflip(){
	var lPVcloseImg = document.getElementById('lPVclose-img');
	if(/btn.png/.test(lPVcloseImg.src)){
		lPVcloseImg.src = baseLocUrl + '/skin/frontend/dutch/dutch/images/map-modal-close-btn-wh.png';
	}
	else{
		lPVcloseImg.src = baseLocUrl + '/skin/frontend/dutch/dutch/images/map-modal-close-btn.png';
	}
}


function lPVEradicator(){
	var deathRow = new Array('lPVback', 'lPVbox', 'lPVbox');
	for(var i = 0; i< deathRow.length; i++){
		var parent = document.getElementById(deathRow[i]).parentNode;
		var inmate = document.getElementById(deathRow[i]);
		parent.removeChild(inmate);
	}
}

//Locations Carousel


function locAllCarousel(direction){
	
	var carousel = document.getElementById('locations-all-carousel');
	if(!carousel.style.left){
		carousel.style.left = 0;
	}
	var leftNow = parseInt(carousel.style.left);
	if(direction == 'left'){
		var Targ = leftNow - 480;
		locAllCarMove(carousel,Targ);
	}
	if(direction == 'right'){
		var Targ = leftNow;
		carousel.style.left = (leftNow - 480) + 'px';
		var locList = carousel.children;
		carousel.insertBefore(locList[11], carousel.firstChild);
		carousel.insertBefore(locList[11], carousel.firstChild);
		locAllCarMoveR(carousel,Targ);
	}
		
}

function locAllCarMove(carousel, targ){
	var leftCurrent = parseInt(carousel.style.left);
	if(leftCurrent > targ){
		carousel.style.left = (leftCurrent - 10) + 'px';
		locAllCarTimer = setTimeout(function(){locAllCarMove(carousel, targ)}, 1);
		
	}
	else{
		clearTimeout(locAllCarTimer);
		var locList = carousel.children;
		var locAdd = locList[0];
		var locAdd2 = locList[1];
		carousel.appendChild(locAdd);
		carousel.appendChild(locAdd2);
		carousel.style.left = (targ + 480) + 'px';
		//locAllCarTimer = setTimeout(function(){locAllCarMove(carousel, targ)}, 3000);			
	}
}


function locAllCarMoveR(carousel, targ){
	var leftCurrent = parseInt(carousel.style.left);
	if(leftCurrent < targ ){
		carousel.style.left = (leftCurrent + 10) + 'px';
		locAllCarTimer = setTimeout(function(){locAllCarMoveR(carousel, targ)}, 1);
		
	}

}


function locAllCarPause(){
	clearTimeout(locAllCarTimer);	
	
}

function locAllCarReStart(e){
	if(!e) var e = window.event;
	var target = (window.event) ? e.scrElement : e.target;
	var relTarget = (e.relatedTarget) ? e.relatedTarget : e.toElement;

	if(relTarget.className == 'logo'){
		var carousel = document.getElementById('locations-all-carousel');
		var targ = -240;
		locAllCarMove(carousel, targ);
	}	
	if(relTarget.className == 'header'){
		var carousel = document.getElementById('locations-all-carousel');
		var targ = -240;
		locAllCarMove(carousel, targ);
	}	
	if(relTarget.className == 'page'){
		var carousel = document.getElementById('locations-all-carousel');
		var targ = -240;
		locAllCarMove(carousel, targ);
	}
		
}


//Hero Carousel
/*old

function heroCarousel(){
	var carousel = document.getElementById('home-hero-slider');
	if(carousel){
		if(!carousel.style.left){
			carousel.style.left = -100 + 'px';
		}
		var leftNow = parseInt(carousel.style.left);
		var heroWidth = carousel.children[0].offsetWidth;
		var leftTarg = (leftNow - heroWidth);
		heroCarMove(carousel,leftTarg,heroWidth);	
	}
}

function heroCarMove(carousel, targ, heroWidth){
	var leftCurrent = parseInt(carousel.style.left);
	if(leftCurrent > targ){
		carousel.style.left = (leftCurrent - 1) + 'px';
		heroCarTimer = setTimeout(function(){heroCarMove(carousel, targ, heroWidth)}, 50);
	}
	else{
		carousel.style.left = (leftCurrent - 1) + 'px';
		var heroList = carousel.children;
		var heroAdd = heroList[0];
		carousel.appendChild(heroAdd);
		carousel.style.left = (targ + heroWidth) + 'px';
		heroCarTimer = setTimeout(function(){heroCarousel()}, 50);			
	}
}

function heroCarRestart(e){
	var relTarget = (e.relatedTarget) ? e.relatedTarget : e.toElement;
	var carousel = document.getElementById('home-hero-slider');
	var leftNow = parseInt(carousel.style.left);
	var heroWidth = carousel.children[0].offsetWidth;
	var leftTarg = (-(heroWidth + 100));
	if(relTarget.className && relTarget.className == 'hh-slider' || relTarget.parentNode.className && relTarget.parentNode.className == 'hh-slider' || relTarget.offsetParent && relTarget.offsetParent.id == 'home-hero-slider' || relTarget.id == 'home-hero-slider'){
		return;
	}
	else{
		clearTimeout(heroCarTimer);
		heroCarMove(carousel,leftTarg,heroWidth);
	}
}

*/

//Updated Hero 

function heroCntrlRght(){
	var heroCCarousel = document.getElementById('hero-control-slide-wrap'); // Locate the Hero Control Slider #hero-control-slide-wrap
	if(!heroCCarousel.style.left){
		heroCCarousel.style.left = 0 + 'px';	
	}
	moveHeroCC();
	
	function moveHeroCC(){   // reposition the div
		var currPos = parseInt(heroCCarousel.style.left);
		if( currPos > -150){
			heroCCarousel.style.left = (currPos - 4) + 'px';
			heroCCTimer = setTimeout(function(){moveHeroCC()}, 1); 			
		}
		else{
			clearTimeout(heroCCTimer);
			var heroCCList = heroCCarousel.children;
			heroCCarousel.appendChild(heroCCList[0]); // appendChild
			heroCCarousel.style.left = 0 + 'px';// adjust position
		}
	
	}
	
}


function heroCntrlLft(){
	var heroCCarousel = document.getElementById('hero-control-slide-wrap'); // Locate the Hero Control Slider #hero-control-slide-wrap
	if(!heroCCarousel.style.left){
		heroCCarousel.style.left = 0 + 'px';	
	}
	var heroCClist = heroCCarousel.children; // create an array of the li elements
	var movingLi = (heroCClist.length - 1);

	heroCCarousel.style.left = -150 + 'px'; // reposition the ul to hide the new first child
	heroCCarousel.insertBefore(heroCClist[movingLi], heroCClist[0]);	//place the last li at the front of the list
	
	moveHeroCCL();
	
	function moveHeroCCL(){
		var currPos = parseInt(heroCCarousel.style.left);
		if(currPos < 0){
			heroCCarousel.style.left = (currPos + 4) + 'px';
			heroCCTimerL = setTimeout(function(){moveHeroCCL()}, 2);	
		}
		else{
			clearTimeout(heroCCTimerL);	
		}
	}
	
	
}



//original heroCntrlFade fucntion

function heroCntrlFade(target){
	
	var heroGraphic	= document.getElementById('hero-graphic');
	if(target.tagName == "IMG" && target.parentNode.tagName == "A"){
		var targHtml = target.parentNode.parentNode.innerHTML;
	}
	else{
		var targHtml = target.parentNode.innerHTML;	
	}
	//new Effect.Opacity(heroGraphic, {from: 1.0, to: 0, duration: 1});
	//setTimeout(function(){heroGraphic.innerHTML = targHtml; new Effect.Opacity(heroGraphic, {from: 0, to: 1.0, duration: 1});}, 1000);
	
	heroGraphic.innerHTML = targHtml;
}


//experimental heroCntrlFade function
 function heroCntrlFade2(target){
	 if(heroTime){clearTimeout(heroTime);}
	 //fade.cancel();
	 var heroImgCur = $('hero-graphic').select('img')[0];
	 var heroGraphic = document.getElementById('hero-graphic');
	 
	 if(target.tagName == "IMG" && target.parentNode.tagName == "A"){
		var targHtml = target.parentNode.parentNode.innerHTML;
	}
	else{
		var targHtml = target.parentNode.innerHTML;	
	}
	
	var newHero = document.createElement('li');
	newHero.className = 'hh-slider emerging-hero';
	newHero.innerHTML = targHtml;
	document.getElementById('home-hero-slider').appendChild(newHero);
	heroGraphic.fade({duration: 5.0, from: 1, to: 0});
	var heroTime = setTimeout(function(){document.getElementById('home-hero-slider').removeChild(heroGraphic); newHero.className = 'hh-slider'; newHero.id = 'hero-graphic';setTimeout(function(){heroCrossFade(heroCrossFadeCount)}, 5000)}, 5005);
	
	
	
	//heroGraphic.fade({duration: 1.0, from: 1, to: 0, queue: 'end'});
	/*//if(heroCrossFadeTimer){clearTimeout(heroCrossFadeTimer);}
	// grab the current hero image 
	var heroImgCur = $('hero-graphic').select('img')[0];
	//capture the current hero graphic's li as a separate variable
	var heroGraphic	= document.getElementById('hero-graphic');
	//establish the new hero elements innerHTML
	if(target.tagName == "IMG" && target.parentNode.tagName == "A"){
		var targHtml = target.parentNode.parentNode.innerHTML;
	}
	else{
		var targHtml = target.parentNode.innerHTML;	
	}
	//remove the current hero and its container
	document.getElementById('home-hero-slider').removeChild(heroGraphic);
	//add the new graphic to the DOM
	var newHero = document.createElement('li');
	newHero.id = 'hero-graphic';
	newHero.className = 'hh-slider';
	newHero.innerHTML = targHtml;
	newHero.style.background = 'pink url(' + heroImgCur.src + ')';
	newHero.style.minWidth = 780 + 'px';
	newHero.style.minHeight = 400 + 'px';
	newHero.select('img')[0].fade({duration: 1.0, from: 0, to: 1, queue: 'end'});
	document.getElementById('home-hero-slider').appendChild(newHero);
	
	
	//newHero.select('img')[0].fade({duration: 1.5, from: 0, to: 1.0});
	heroCrossFadeTimer = setTimeout(function(){heroCrossFade(heroCrossFadeCount)}, 3000)
*/

//restarted on April 11, 2011
//var heroImgCur = $('hero-graphic').select('img')[0];


}


function heroCrossFade(count){
	/* make an array from the hh-control-item li images */

	var heroImgArray = $$('li.hh-control-item');
	heroCntrlFade2(heroImgArray[count].select('img')[0]);
	//console.log(heroImgArray[count].select('img')[0]);
	//console.log('coming in ' + count);
	if(count < (heroImgArray.length - 1)){
		count++;
	}else{
		count = 0;	
	}
	//heroCrossFadeTimer = setTimeout(function(){heroCrossFade(count)}, 5000);
	//clearTimout(heroCrossFadeTimer);
	heroCrossFadeCount = count;
	//console.log(heroCrossFadeCount)

	/* set the z-index value of the current hero image */
	//var heroImgCur = $('hero-graphic').select('img')[0];
	//heroImgCur.style.zIndex = 2;
			
	/* add a new image to the DOM underneith the current hero. Manage necessary styles
	for(var i=0; i<heroImgArray.length; i++){
			
	} */
	/*var newHero = document.createElement('li');
	newHero.className = 'hh-slider';
	newHero.innerHTML = '<a id="lPVclose" href=" "><img id="lPVclose-img" src="' + baseLocUrl + '/skin/frontend/dutch/dutch/images/map-modal-close-btn.png" alt="close"/></a>';
	document.getElementById('lPVbox').appendChild(lPVclose);	*/
	
	/* Fade the top -- original -- image */
	
	/* set a timer to restart the function, using the next image in the array */
	
	 
}



//Preload images baby

preloadImgs();
function preloadImgs(){
	var imgUrl = baseLocUrl + 'skin/frontend/dutch/dutch/images';
	imgObj = new Image();
	
	images = new Array();
	images[0] =  imgUrl + 'loc-map-back-v083110.jpg';
	for(var i =0; i < images.length; i++){
		imgObj.src=images[i];	
	}
	
}
	
	

//Scroll to the top of the logo

function initScroll(){

	//Effect.ScrollTo('header', { offset: 5});
	//console.log(window.pageYOffset);
	//locationDiv = document.getElementById('locations').style;
	//locationDiv.display = 'none';
	/*
	if(window.pageYOffset == 0 || document.body.scrollTop == 0){
		scrollBy(0,335);	
	}
	*/
	
}

function locScroll(){
	locationDiv = document.getElementById('locations').style;
	//locationDiv.display = 'block';
	Effect.BlindDown('locations', { duration: 1.0 });
	
	//Effect.ScrollTo('locations', {duration: '1', offset: -20});
		

}


//Scroll to the contact form


function contactScroll(){
	Effect.ScrollTo('footer-postcard', {duration: '2', offset: 5});	
}





// VIDEO Section

function changeVideo(videoId){
	var player = document.getElementById('video-div');
	var vidTitle = document.getElementById('video-main-title');
	var vidImg = document.getElementById('video-img-' + videoId);
	player.innerHTML = '';
	player.innerHTML = '<p><object id="theplayer" width="700" height="418"><param name="movie" value="http://www.youtube.com/v/' + videoId + '?fs=1&amp;hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/' + videoId + '?fs=1&amp;hl=en_US&amp;rel=0&amp;enablejsapi=1&amp;&amp;version=3&amp;playerapiid=ytplayer" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="700" height="418"></embed></object></p>';

	vidTitle.innerHTML = vidImg.alt;
	
	
	Cufon.replace('#video-main-title', {
		fontFamily: 'ChunkFiveRegular'
	});

}

//AUDIO Section

function addPodPlayer(target){
	var podUrl = target.id;
	var flashvars = {audio: podUrl, autoplay:"false"};
	var params = {allowfullscreen:false, menu:"false", bgcolor:"#ffffff", wmode:"opaque", AllowScriptAccess:"always" };
	var attributes = {}; 
	var playerUrl = baseLocUrl + 'lib/Flash/bin/AudioPlayer.swf';
	swfobject.embedSWF( playerUrl, target.id, "265", "25", "10", "expressInstall.swf", flashvars, params, attributes); 
	/*target.innerHTML = '<object id="flashContent" width="265" height="25" type="application/x-shockwave-flash" data="' + baseLocUrl + 'lib/Flash/bin/AudioPlayer.swf" style="visibility:visible;"><param name="allowfullscreen" value="false"><param name="menu" value="false"><param name="bgcolor" value="#333333"><param name="wmode" value="opaque"><param name="AllowScriptAccess" value="always" ><param name="flashvars" value="audio=' + podUrl + '&autoplay=false"></object>';*/	
}




//Contest coupons 
function contestCoupon(target){
		var printWin = window.open('','');
		printWin.document.write('<html><head></head><body><img src="' + target.src + '" alt="image to print" /></body></html>');
		printWin.print(); 
		if (navigator.appName != 'Microsoft Internet Explorer') printWin.window.close();
	
}


//4HFFA Discount Card Printer 
function fourhffaCardPrint(target){
		var printWin = window.open('','');
		printWin.document.write('<html><head></head><body><img src="' + target.src + '" width="300" alt="image to print" /></body></html>');
		printWin.print(); 
		//if (navigator.appName != 'Microsoft Internet Explorer') printWin.window.close();
	
}



//Flyers, Coupons, and Promotions

function printCoupon(target){
	var targPapa = target.parentNode.parentNode.parentNode;
	var targFam = targPapa.children;
	for(var i =0; i < targFam.length; i++){	
		if(targFam[i].className = "coupon-img"){
		var printWin = window.open('','');
		printWin.document.write('<html><head></head><body><img src="' + targFam[i].src + '" alt="image to print" /></body></html>');
		printWin.print(); 
		//printWin.close();
		 if (navigator.appName != 'Microsoft Internet Explorer') printWin.window.close();

		 break;	
		}
	}
}


function emailCoupon(target){
	if(!document.getElementById('couponModal')){
		var parentDiv = target.parentNode.parentNode.parentNode;
		var posLeft = target.offsetLeft;
		var posTop = target.offsetTop
		if(/[coupon]/.test(parentDiv.className)){
			for(var i =0; i < parentDiv.children.length; i++){
				if(parentDiv.children[i].className == 'coupon-img'){
					var couponUrl = parentDiv.children[i].src;
					var couponAlt = parentDiv.children[i].alt;
				}
			}
			var curtainModal = document.createElement('div');
			curtainModal.id = 'curtainModal';
			var couponModal = document.createElement('div');
			couponModal.id = 'couponModal';
			couponModal.innerHTML = '<img id="close-coupon-modal" src="' +  baseLocUrl + '/skin/frontend/dutch/dutch/images/map-modal-close-btn-wh.png" alt="close"/><form  class="email-coupon" method="post" action="' + baseLocUrl + 'index.php/flyers-coupons-promotions"><fieldset><legend>Send Via Email</legend><ul><li><label for=emname>Your Name:</label><input id=emname type=text name=emname required></li><li><label for=sendto>Send To:</label><input id=sendto type=text name=sendto required></li><li><label for=sendfrom type=text name=sendfrom required>Send From:</label><input id=sendfrom type=text name=sendfrom></li><li><label for=subject>Subject:</label><input id=coupon-subject type=text name=subject required></li></ul></fieldset><fieldset><label id=mess-label for=emmessage>Your Message</label><textarea id=emmessage name=emmessage></textarea></fieldset><fieldset><input type=hidden value="' + couponUrl + '" name=couponUrl /></fieldset><fieldset><button type=submit>Submit</button></fieldset></form><!--end email-coupon--><div id="coupon-img-thumb"><img src="' + couponUrl + '" alt="' + couponAlt + '"/></div>';		
		}
			var wrap = document.getElementById('wrapper');
			wrap.appendChild(curtainModal);
			wrap.appendChild(couponModal);


			Cufon.replace('#couponModal', {
				fontFamily: 'Lucida Handwriting',
				textShadow: '#c5c5c5 0 0 1px'
			});
			couponModal.style.top = (target.offsetTop + 340) + 'px';
			if(isIe() == 7){//compensate for IE7 issue
				if((target.offsetLeft + 645) < document.width){
					couponModal.style.left = (target.offsetLeft + 25) + 'px';
				}
				else{
					couponModal.style.left = (target.offsetLeft + 326) + 'px';
				}
			}
			else{
				if((target.offsetLeft + 645) < document.width){
					couponModal.style.left = (target.offsetLeft + 25) + 'px';
				}
				else{
					couponModal.style.left = (target.offsetLeft - 325) + 'px';
				}
			}
	}
		
}






function textCoupon(target){
	var parentDiv = target.parentNode.parentNode.parentNode;
	var posLeft = target.offsetLeft;
	var posTop = target.offsetTop
	if(/[coupon]/.test(parentDiv.className)){
		for(var i =0; i < parentDiv.children.length; i++){
			if(parentDiv.children[i].className == 'coupon-img'){
				var couponUrl = parentDiv.children[i].src;
				var couponAlt = parentDiv.children[i].alt;
			}
		}
		var curtainModal = document.createElement('div');
		curtainModal.id = 'curtainModal';
		var tCouponModal = document.createElement('div');
		tCouponModal.id = 'tCouponModal';
		tCouponModal.innerHTML = '<img id="close-coupon-modal" src="' +  baseLocUrl + '/skin/frontend/dutch/dutch/images/map-modal-close-btn-wh.png" alt="close"/><form  class="text-coupon" method="post" action="' + baseLocUrl + 'index.php/flyers-coupons-promotions"><fieldset><legend>Send Via Text Message</legend><ul><li><label for=tname>Your Name:</label><input id=tname type=text name=tname required></li><li><label for=tsendto>To Number:</label><input id=tsendto type=text name=tsendto required></li><li><label for=tsendfrom type=text name=tsendfrom required>From Number:</label><input id=tsendfrom type=text name=tsendfrom></li><li><label for=subject>Subject:</label><input id=coupon-subject type=text name=subject required></li><li><label for=carrier>To Carrier:</label><select name=carrier id=carrier required><option value="message.alltel.com">Alltel</option><option value="txt.att.net">AT&amp;T</option><option value="tmomail.net">T-Mobile</option><option value="vmobl.com">Virgin Mobile</option><option value="messaging.sprintpcs.com">Sprint</option><option value="vtext.com">Verizon</option><option value="messaging.nextel.com">Nextel</option><option value="mms.uscc.net">US Cellular</option></select></li></ul></fieldset><fieldset><label id=tmess-label for=tmessage>Your Message:</label><textarea id=tmessage name=tmessage></textarea></fieldset><fieldset><input type=hidden value="' + couponUrl + '" name=couponUrl /></fieldset><fieldset id="tsubmitter"><button type=submit>Submit</button></fieldset></form><!--end email-coupon-->';		
	}
		var wrap = document.getElementById('wrapper');
		wrap.appendChild(curtainModal);
		wrap.appendChild(tCouponModal);
		Cufon.replace('#tCouponModal', {
			fontFamily: 'Lao UI',
			textShadow: '#c5c5c5 0 0 1px'
		});
		tCouponModal.style.top = (target.offsetTop + 150) + 'px';
		if(isIe() == 7){
			
			if((target.offsetLeft + 645) < document.width){
				tCouponModal.style.left = (target.offsetLeft + 525) + 'px';
			}
			else{
				tCouponModal.style.left = (target.offsetLeft + 325) + 'px';					
			}
		}
		else{
			if((target.offsetLeft + 645) < document.width){
				tCouponModal.style.left = (target.offsetLeft + 25) + 'px';
			}
			else{
				tCouponModal.style.left = (target.offsetLeft - 325) + 'px';					
			}
		}
		
}


function destroyCoupon(){
	if(document.getElementById('couponModal')){
		var inmate = document.getElementById('couponModal');
	}
	else{
		var inmate = document.getElementById('tCouponModal');	
	}
	
	var inmate2 = document.getElementById('curtainModal');
	var wrap = document.getElementById('wrapper');
	wrap.removeChild(inmate);
	wrap.removeChild(inmate2);
}

//NORMAL FLYER 1255 by 1215  EFLYER 1255 by 813
function pageTurner(e){
	if(!e) var e = window.event; // compensate for browser differences
	var target = e.target || e.srcElement;
	var targLink = target.href || target.src;
	var regEx = /\S{16}$/;
	var regArr = regEx.exec(targLink);
	var swfName = regArr[0].replace(/\S{3}$/, "swf");
	var wrap = document.getElementById('wrapper');
	var flyerModal = document.createElement('div');
	flyerModal.id = 'flyerModal';
	var flyerTurner = document.createElement('div');
	flyerTurner.id = 'flyerTurner';
	flyerTurner.innerHTML = '<img id="close-flyer-modal" src="' +  baseLocUrl + '/skin/frontend/dutch/dutch/images/map-modal-close-btn-wh.png" alt="close"/><object id="FlashID" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="1255" height="1215"><param name="movie" value="' + baseLocUrl + 'media/import/flyers/081011-flyer.swf"><param name="quality" value="high"><param name="wmode" value="opaque"><param name="swfversion" value="6.0.65.0"><!--ThisparamtagpromptsuserswithFlashPlayer6.0r65andhighertodownloadthelatestversionofFlashPlayer.Deleteitifyoudontwantuserstoseetheprompt.--><param name="expressinstall" value="' + baseLocUrl + 'Scripts/expressInstall.swf"><!--Nextobjecttagisfornon-IEbrowsers.SohideitfromIEusingIECC.--><!--[if!IE]>--><object type="application/x-shockwave-flash" data="' + baseLocUrl + 'media/import/flyers/081011-flyer.swf" width="1255" height="1215"><!--<![endif]--><param name="quality" value="high"><param name="wmode" value="opaque"><paramname="swfversion" value="6.0.65.0"><param name="expressinstall" value="' + baseLocUrl + 'Scripts/expressInstall.swf"><!--ThebrowserdisplaysthefollowingalternativecontentforuserswithFlashPlayer6.0andolder.--><div><h4>Content on this page requires a newer version of Adobe Flash Player.</h4><p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="GetAdobeFlashplayer" width="112" height="33"/></a></p></div><!--[if!IE]>--></object><!--<![endif]--></object><p>Click or drag a page to turn it.</p>';
	wrap.appendChild(flyerModal);
	wrap.appendChild(flyerTurner);
	if(!window.pageYOffset == 0 || document.body.scrollTop == 0){
		scrollTo(0,10);	
	}
		
}



function destroyFlyer(){
	var inmate = document.getElementById('flyerModal');
	var inmate2 = document.getElementById('flyerTurner');
	var wrap = document.getElementById('wrapper');
	wrap.removeChild(inmate);
	wrap.removeChild(inmate2);	
	
}


