/* Shaw Media Master Sites Drop Down Insertion */
/* 
	Implementation:
		Add a div with the id of 'masterSitesDropdown' followed by a script call to this script on your page where you want this dropdown to appear.
	
	If jQuery is present on the page, a document ready function will be run and the drop down added using no document.write functions.
	If jQuery is NOT present on the page, the masterSitesDropdown div will be removed and recreated with the drop down added inside.  All of this will be using document.write functions.	
*/
// either way jQuery or not the options are the same.  Set them here.
theOptions = '<option value="#">Shaw Media Sites</option>';
theOptions += '<optgroup label="Television">';
	theOptions += '<option value="http://www.globaltv.com/">Global TV </option>';
	theOptions += '<option value="http://www.foodnetwork.ca/">Food Network </option>';
	theOptions += '<option value="http://www.hgtv.ca/">HGTV</option>';
	theOptions += '<option value="http://www.history.ca/">History</option>';
	theOptions += '<option value="http://www.showcase.ca/">Showcase</option>';
	theOptions += '<option value="http://www.slice.ca/">Slice</option>';
	theOptions += '<option value="http://www.tvtropolis.com/">TVTropolis</option>';
	theOptions += '<option value="http://www.bbccanada.com/">BBC Canada </option>';
	theOptions += '<option value="http://www.dejaviewtv.ca/">DejaView</option>';
	theOptions += '<option value="http://www.twisttv.ca/">Twist TV </option>';
	theOptions += '<option value="http://www.diy.ca/">DIY Network </option>';
	theOptions += '<option value="http://www.foxsports.ca/">Fox Sports World </option>';
	theOptions += '<option value="http://www.globalreality.ca/">Global Reality</option>';
	theOptions += '<option value="http://www.ifctv.ca/">IFC</option>';
	theOptions += '<option value="http://www.movietimetv.ca/">Movietime</option>';
	theOptions += '<option value="http://www.mysterytv.ca">Mystery TV </option>';
	theOptions += '<option value="http://natgeotv.com/ca/">National Geographic </option>';
	theOptions += '<option value="http://www.action-tv.ca">Showcase Action </option>';
	theOptions += '<option value="http://www.diva-tv.ca">Showcase Diva </option>';
theOptions += '</optgroup>';
theOptions += '<optgroup label="News">';
	theOptions += '<option value="http://www.globalnews.ca">Global News</option>';
	theOptions += '<option value="http://www.globalnational.com">Global National</option>';
	theOptions += '<option value="http://www.globaltvbc.com">Global BC</option>';
	theOptions += '<option value="http://www.globaltvcalgary.com">Global Calgary</option>';
	theOptions += '<option value="http://www.globaltvedmonton.com">Global Edmonton</option>';
	theOptions += '<option value="http://www.globallethbridge.com">Global Lethbridge</option>';
	theOptions += '<option value="http://www.globalsaskatoon.com">Global Saskatoon</option>';
	theOptions += '<option value="http://www.globalregina.com">Global Regina</option>';
	theOptions += '<option value="http://www.globalwinnipeg.com">Global Winnipeg</option>';
	theOptions += '<option value="http://www.globaltoronto.com">Global Toronto</option>';
	theOptions += '<option value="http://www.globalmontreal.com">Global Montreal</option>';
	theOptions += '<option value="http://www.globalmaritimes.com">Global Maritimes</option>';
	theOptions += '<option value="http://www.chbcnews.ca/">CHBC News – Kelowna</option>';
theOptions += '</optgroup>';
// Check for jQuery
if(typeof(jQuery) == 'function'){
	// Add a doc ready function to manipulate the dom when it is ready
	jQuery(document).ready(function($){
		// Calling jQuery first and passing the $ alias to the function ensures that the internal code will work using the $ alias whether or not jQuery.noConflict() has been called.
		theHTML = '<form><select id="masterSitesSelect">';
		theHTML += theOptions;
		theHTML += '</select></form>';
		// insert the form and select into the desired div
		$('#masterSitesDropdown').html(theHTML);
		// add an event function to redirect the user when they choose a site.
		$('#masterSitesSelect').change(function(){
			window.location = $(this).val();
		});
	});
} else {
	// Non jQuery code.  
	theHTML = '<form style="height:10px;"><select id="masterSitesSelect" onchange="redirect(this)">';
	theHTML += theOptions;
	theHTML += '</select></form>';
	var original = document.getElementById('masterSitesDropdown');
	original.parentNode.removeChild(original);
	document.write('<div id="masterSitesDropdown">'); document.write(theHTML); document.write('</div>');
	document.write('<scr'); document.write('ipt type="text/javascript">function redirect(selectObj) {document.location = selectObj.options[selectObj.selectedIndex].value;}'); /* The <script> tag must remain broken up in this way */
	document.write('</scr'); document.write('ipt>'); /* The </script> tag must remain broken up in this way */
}
