$(document).ready(function(){
	//updateCategories(dataSet);
  $(".profileForm [type='text']").css({"border":"solid 1px #cccccc","width":"212px","padding":"3px","color":"#838383","font-size":"11.4px"});
  $(".profileForm [type='password']").css({"border":"solid 1px #cccccc","width":"212px","padding":"3px","color":"#838383","font-size":"11.4px"});
  
  $(".profileForm2 [type='text']").css({"border":"solid 1px #cccccc","width":"212px","padding":"3px","color":"#838383","font-size":"11.4px"});
  $(".profileForm2 [type='password']").css({"border":"solid 1px #cccccc","width":"212px","padding":"3px","color":"#838383","font-size":"11.4px"});
  
  //profile form
  $(".progression1").css({"display":"none"});
  $(".progression2").css({"display":"none"});
  $(".progression3").css({"display":"none"});
  $(".progression4").css({"display":"none"});
  $(".progression5").css({"display":"none"});
  $(".pop_1_form_overlay").css({"display":"none"});
   
  //accordion left
  $('#accordion .head').click(function() {
		$(this).next().toggle();
		$(this).toggleClass("current");
		return false;
	}).next().hide();
	$('#accordion .head').next().show()
	$('#accordion .head').toggleClass("current");
	
	
   //accordion right
  $('#accordion-right .head').click(function() {
		$(this).next().toggle();
		$(this).toggleClass("current");
		return false;
	}).next().hide();
	$('#accordion-right .head').next().show()
	$('#accordion-right .head').toggleClass("current");
  
    
  /*$('.content p.title').click(function(){
  			$('.popUp_2_lightBox').show();
			$(this).css({"cursor":"pointer"})
  		});*/
		/*var triggers = $("a.modalInput").overlay({ 
			// some expose tweaks suitable for modal dialogs 
			expose: { 
			color: '#333',
			loadSpeed: 200,
			opacity: 0.5
			},
			closeOnClick: false 
		});*/
		$("#yesno").overlay({ 
			// some expose tweaks suitable for modal dialogs 
			expose: { 
			color: '#ffffff',
			loadSpeed: 200,
			opacity: 0.8
			},
			closeOnClick: false,
			top: '1%',
			onBeforeClose: function(e){
				if (scExp.currentScenarioObject != null){
					var isShown = scExp.currentScenarioObject.formShown;
					// if the exp dialog already shown, just close the asset lightbox
					if (isShown)
						return true;
					
					// close the exp dialog
					scExp.closeAsset();
					
					// check and see if the asset lightbox should be kept opened
					if (scExp.currentScenarioObject.spawnOnAction == "onClose" && !isShown){
						scExp.currentScenarioObject.formShown = true;
						return false;
					}
				}
			}
		});	
		

	//tool tip
	$("div.tip").tooltip({              
	// use single tooltip element for all tips         
	tip: '#tooltip',
	cancelDefault:true,
	onBeforeShow: function() {
		
		$("#toolTipLabel").html(this.getTrigger().attr("toolTip"));
        //this.getTrigger().fadeTo("slow", 0.8); 
    }, 
	// tweak the position         
	offset: [-10, 75],
	predelay: 	200,
	relative: false
	});
	
	
	$("a.tab").click(function () {
		// switch all tabs off
		$(".active").removeClass("active");
		// switch this tab on
		$(this).addClass("active");
		// slide all content up
		$(".pop_ac_slide").fadeOut("slow");
		// slide this content up
		var content_show = $(this).attr("title");
		$("#"+content_show).toggle();
	});
	
	$('.pop_1_form').show();
	$('a.popUp_3_close').click(function(){
		$('.pop_1_form').hide();
	});

	$("#pageInfo").toggle();

	$("#popInstructions").toggle("slide");

	$('a.closePopInst').click(function() {
		$('#popInstructions').toggle("slide"); 
		return false;
	  });

	runFilterSetUp();
	
});



// after the 8 seconds delay, hide it regardless it's shown or hidden
setTimeout(function() {
	$('#pageInfo').hide();} ,8000);

runFilterSetUp = function(){
	
	telusFilterTool.initFilters();
	//var searchTermArr = window.location.search.split("=");
	
	if(resourcePage){
		buildDate();
		//tagcloud from home
		var searchName = gup("search");
		var searchType = gup("searchType");
		if(searchName != ""){
			
			telusFilterTool.updateListingsFromTag(unescape(searchName));		
		//fav or hist from home		
		}else if(searchType != ""){
			telusFilterTool.updateListingsFromTag(unescape(searchType),true);	
		}else{
			telusFilterTool.updateListings(false);		
		}
		loadFlashFeature(filterNames[userType],true);
	}else{
		//update dataset with first item from business datasert
		var dataSetName = "dataSet_"+userType;
		dataSet = dataSetLib[filterNames[userType]];
		//dataSet.unshift(this[dataSetName][0]);	//VC: request to remove the feature item from the newly added list	
		//dataSet
		loadFlashFeature(filterNames[userType]);
		buildDate();
		telusFilterTool.updateListings(false);	
	}
	var assetID = gup("assetID");
	
	if(assetID != ""){		
		for(var i = 0;i<dataSet.length;i++){
			if(dataSet[i].id == assetID){
				//alert(gup("pos"));
				//showLightBox('#yesno',dataSet[i].type,dataSet[i].id,gup("pos"),i,trackFeatureLink);
				showLightBox('#yesno',dataSet[i].type,dataSet[i].id,gup("pos"),i);
				break;
			}
		}	
	}
	
}

function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

loadFlashFeature = function(id,short){

	/*var dataSetVars = "?featureLength="+dataSet.length;
	for(var i = 0;i<dataSet.length;i++){
		dataSetVars+="&type"+i+"="+dataSet[i].type;
		dataSetVars+="&id"+i+"="+dataSet[i].id;
		dataSetVars+="&featureImage"+i+"="+dataSet[i].featureImage;
		dataSetVars+="&title"+i+"="+escape(dataSet[i].featureBigText);
		dataSetVars+="&subtitle"+i+"="+escape(dataSet[i].featureLittleText);
		
		
	}*/
	
	if (typeof(user_locale) != "undefined" && user_locale == "fr_CA"){
		var lang = "fr";	
	}else{
		var lang = "en";
	}
	
	
	//alert(dataSet[0].featureLittleText)
	var dataSetVars = "?businessSize="+id+"&lang="+lang;
	var basePos = window.location.href.lastIndexOf("/");
		
		
	dataSetVars += "&baseUrl="+window.location.href.slice(0,basePos+1);
	
	//return;
	var frameHeight = 283;	
	var showOpen = "&showOpen=true";
	if(short){
		frameHeight = 87;	
		showOpen = "&showOpen=false";
		$('#featureFlash').height(95);
		
	}
	
	var flashDoc = '<iframe id="flashFeatureIframe" src="featureFlash.html'+dataSetVars+showOpen+'" width="582" height="'+frameHeight+'" border="0" marginwidth="1" marginheight="1" frameborder="0" scrolling="no"></iframe>';
						
	$('#featureFlash').html(flashDoc);					

}

moveFeatureFrame =function(dir){
	if(dir=="up"){
	//	alert("up");		
		$('#flashFeatureIframe').attr("height","87");	
		$('#featureFlash').height(95);
	}else{
	//	alert("down")
		$('#flashFeatureIframe').attr("height","283");	
		$('#featureFlash').height(283);
	}
}
