window.onload = function()
{
	createSwftype(".swfMainArticleTitle", "flash/SwftypeBentonSans-Black.swf", "css/swftype.css", 295, 27, false, "height", false);
	createSwftype(".swfColumnHeading", "flash/SwftypeBentonSans-Black.swf", "css/swftype.css", 313, 27, false, "height", false);
	createSwftype(".swfBlogCategoryHeading", "flash/SwftypeBentonSans-Black.swf", "css/swftype.css", 536, 27, false, "height", false);
	createSwftype(".swfBlackTitleBar", "flash/SwftypeBentonSans-Black.swf", "css/swftype.css", 600, 27, false, "all", false);
}

function navOver(imgTag)
{        
	var theImage = imgTag;	
	if(theImage.src.indexOf("_off.") != -1)	
	{
		theImage.src = theImage.src.replace("_off.","_on.");		
	}
	else	
	{
		theImage.src = theImage.src.replace("_on.","_off.");	
	}
}

function requestReviewNav(tabName)
{
	if(tabName == 'request')
	{
		document.getElementById(tabName).style.display = "block";
		document.getElementById("review").style.display = "none";
		document.getElementById("infoBtn").className = "btnRequestInfo btnRequestInfoOn";
		document.getElementById("reviewBtn").className = "btnCustomerReviews";
	}
	else if(tabName == 'review')
	{
		document.getElementById(tabName).style.display = "block";
		document.getElementById("request").style.display = "none";
		document.getElementById("reviewBtn").className = "btnCustomerReviews btnCustomerReviewsOn";
		document.getElementById("infoBtn").className = "btnRequestInfo";
	}
}

function setColorActive(elem)
{
	elem.style.color = "#000000";
}
function setColorInactive(elem)
{
	elem.style.color = "#999999";
}

function assignClick() 
{
	$(document).ready(function() 
	  {		  
			/* add toggle event to my <dt> */
			$(".dropdown").each(function() 			
			{					               
				var self = $(this);
				$("dt a", this).click(function()
				{					
					$("dd ul", self).toggle();
				})
		});
			
			/* add click event to links in <dd> to pass selectedValue to the parent <dt> */   

			$(".dropdown").each(function() {
				var self = $(this);
				$("dd ul li a", this).click(function() {
					var text = $(this).html();
					$("dt a", self).html(text);
					var relDdl = self.prev().attr("id");
					$("#" + relDdl + " option[value='" + $("span", this).html() + "']").attr('selected', 'selected');
					$("ul", self).hide();
				});
			});


	});
}
  
  function customDDL(id)
  {		
		// reference ID
		var source = $("#" + id);		

		// reference parentID
		var sourceParent = $(source).parent();
		
		// get width of drop down list
		var getWidth = $(source).css("width");
		
		// calculate width for inner dd > ul
		var ulWidth = (parseInt(getWidth) - 2) + "px";  
	
		// hide drop down list
		$(source).css("display","none");

		// get selected <option>
		var sel = source.find("option[selected]");  
		
		// get all <option> elements
		var options = $("option", source);  
	
		/* create <dl> and <dt> with selected value inside it */
		
		// appends a <dl> with my assigned ID to the body tag 
		$(sourceParent).append('<dl id="' + id + 'target" class="dropdown" style="width:' + getWidth + '"></dl>')
		
		// create  definition list and add to my assigned ID
		$("#"+id+"target").append('<dt><a href="#">' + sel.text() + '<span class="value">' + sel.val() + '</span></a></dt>')
		$("#"+id+"target").append('<dd><ul style="width:'+ ulWidth +'"></ul></dd>')
		
		// iterate through all the <option> elements and create UL
		options.each(function()
		{
			$("#"+id+"target dd ul").append('<li><a href="#">' + 
			$(this).text() + '<span class="value">' + 
			$(this).val() + '</span></a></li>');
		});
		assignClick();
}

var PopupLocation = {
	Show: function()
	{
		var elem = document.getElementById("locationsList");
		elem.style.display = "block";
	},
	Hide: function()
	{
		var elem = document.getElementById("locationsList");
		elem.style.display = "none";
	},
	Set: function(location, location_id)
	{
		document.getElementById("theLocation").innerHTML = location;
		document.getElementById("location_id").value = location_id;
		PopupLocation.Hide();
	}
}

var PopupFeaturedLocation = {
	Show: function(id)
	{
		var elem = document.getElementById(id);
		elem.style.display = "block";
	},
	Hide: function(id)
	{
		var elem = document.getElementById(id);
		elem.style.display = "none";
	},
	Set: function(location, location_id, ad_type, ad_keyword)
	{
		// This has now been updated to populate all three featured supplier boxes no matter which box you choose.
		// These values have been hard coded and will need to change if the homepage layout changes.
		
		// Update main location
		$('#location_id').val(location_id);
		$('#theLocation').text(location);
		
		// Repopulate Fashion
		ad_type1 = 1;
		ad_keyword1 = 'fashion_feature';		
		if(document.getElementById("theLocation" + ad_type1))
		{
			document.getElementById("theLocation" + ad_type1).innerHTML = location;		
			// Ajax the results
			$.ajax({			
				type: 'get',
				url: '/suppliers.php',
				data: 'p=FeaturedSuppliers&offset=1&num=10&ad_type=' + ad_keyword1 + '&location_id=' + location_id + '&location_name=' + location + '&resetlocation=true',
				success: function(success){						
					// If no featured suppliers then hide the box, otherwise display all results.
					if(success.indexOf('noresults') != -1)			
					{
						// if no results do not clear featured suppliers
					}
					else
					{						
						var id = '#featuredSuppliers' + ad_type1;
						$(id).html(success);						
						reDoSlider(ad_type1);
					}
				}							 
			});			
			PopupFeaturedLocation.Hide('featuredLocationsList' + ad_type1);
		}	
		
		// Repopulate Beauty
		ad_type2 = 2;
		ad_keyword2 = 'beauty_feature';		
		if(document.getElementById("theLocation" + ad_type2))
		{
			document.getElementById("theLocation" + ad_type2).innerHTML = location;		
			// Ajax the results
			$.ajax({
				type: 'get',
				url: '/suppliers.php',
				data: 'p=FeaturedSuppliers&offset=1&num=10&ad_type=' + ad_keyword2 + '&location_id=' + location_id + '&location_name=' + location + '&resetlocation=true',
				success: function(success){						
					// If no featured suppliers then hide the box, otherwise display all results.
					if(success.indexOf('noresults') != -1)
					{
						// if no results do not clear featured suppliers
					}
					else
					{						
						var id = '#featuredSuppliers' + ad_type2;
						$(id).html(success);						
						reDoSlider(ad_type2);
					}
				}							 
			});			
			PopupFeaturedLocation.Hide('featuredLocationsList' + ad_type2);
		}
		
		// Repopulate Planning
		ad_type3 = 3;
		ad_keyword3 = 'planning_feature';
		if(document.getElementById("theLocation" + ad_type3))
		{
			document.getElementById("theLocation" + ad_type3).innerHTML = location;			
			// Ajax the results
			$.ajax({		
				type: 'get',
				url: '/suppliers.php',
				data: 'p=FeaturedSuppliers&offset=1&num=10&ad_type=' + ad_keyword3 + '&location_id=' + location_id + '&location_name=' + location + '&resetlocation=true',
				success: function(success){						
					// If no featured suppliers then hide the box, otherwise display all results.
					if(success.indexOf('noresults') != -1)			
					{
						// if no results do not clear featured suppliers
					}
					else
					{						
						var id = '#featuredSuppliers' + ad_type3;
						$(id).html(success);						
						reDoSlider(ad_type3);
					}
				}							 
			});			
			PopupFeaturedLocation.Hide('featuredLocationsList' + ad_type3);
		}
	}
}





