// Apply the Highslide settings
hs.graphicsDir = 'css/graphics/';
hs.wrapperClassName = 'draggable-header no-footer';

//hs.outlineType = 'rounded-white';
hs.outlineType = null;
hs.allowMultipleInstances = false;
hs.allowSizeReduction = false;
hs.preserveContent = false;
hs.objectLoadTime = 'after';
hs.align = 'center';
hs.fadeInOut = true;
hs.dimmingOpacity = 0.20;
hs.dimmingGeckoFix = true; //fixes the mac ff2 transp issue
ie6 = document.all && document.fireEvent && document.createComment;
safari = /Safari/.test(navigator.userAgent);

// define the restraining box
hs.useBox = true;

if(ie6) {
    hs.width = 950;
	hs.height = 780;
} else {
	hs.width = 850;
	hs.height = 660;
}

hs.addEventListener(window, 'load', spawnHighSlideFromQueryString);

function spawnHighSlideFromQueryString() {
    var qs = window.location.search;
    var qob = objectFromQueryString(qs);
    if (qob.mv != undefined) {
        spawnHighSlide('http://nv.nimblefish.com/vs/NIMBLEFISH/Content/Public/Advisor/WEBSITE_NV/nf_website_preview.nvml?mv=' + qob.mv);
    } else {
        return;
    }
}

//TURN OFF LOADING BAR
hs.Expander.prototype.onShowLoading = function (sender) {
   return false;
};

//TURN ON AND OFF HTML ELEMENTS THAT EMBED FLASH
hs.Expander.prototype.onAfterExpand = function (sender) {
	//check for team page and safari and swap flash with image
	if(safari){
		if($('teamflash')) {
			$('teamflash').setStyle('display','none');
		    $('teamflashstatic').setStyle('display','block');
		}
    }

    //check for products or case study pages and hide buttons
	if($('navproducts') != null) {
       hideProductButtons();
    } else {
	   hideCaseButtons();
    }

   	//check for home page and safari and swap flash with image
	if(safari){
		if($('teamflash')) {
			$('teamflash').setStyle('display','none');
		    $('teamflashstatic').setStyle('display','block');
		}
    }

}

//TURN ON AND OFF HTML ELEMENTS THAT EMBED FLASH
hs.Expander.prototype.onAfterClose = function(sender) {
	var senderURL = sender.a+"";
	if(ie6) {
	    hs.width = 950;
		hs.height = 780;
	} else {
		hs.width = 850;
		hs.height = 660;
	}
	//check for products or case study pages and show buttons
	if($('navproducts') != null) {
		showProductButtons();
	} else {
		showCaseButtons();
	}
	//check for team page and safari and swap flash back
	if(safari){
		if($('teamflash')) {
			$('teamflash').setStyle('display','block');
		    $('teamflashstatic').setStyle('display','none');
		}
	}
	//check for home page and safari and show flash
	if(senderURL.indexOf('contactform.html') != -1) {
		if(safari){
			if($('navhome')) {
				$('content').setStyle('opacity',1);
			}
	    }
	}
}

function hideCaseButtons() {
	if($('navlist')) {
	    $('navlist').setStyle('display', 'none');
	}
}
function showCaseButtons() {
	if($('navlist')) {
	    $('navlist').setStyle('display', 'block');
	}
}

function hideProductButtons() {
	if($('menubar')) {
	    $('menubar').setStyle('display', 'none');
	}
}
function showProductButtons() {
	if($('menubar')) {
	    $('menubar').setStyle('display', 'block');
	}
}


function spawnHighSlideContactUs() {
	if(ie6) {
	    hs.width = 950;
		hs.height = 780;
	} else {
		hs.width = 850;
		hs.height = 660;
	}
    var el = document.getElementById('contactanchor');
    hs.htmlExpand(el, { objectType: 'iframe' } );

   	//check for home page and safari and hide flash
	if(safari){
		if($('navhome')) {
			$('content').setStyle('opacity',0);
		}
    }
}

function spawnHighSlide(flvarArg) {
    var urlParts = flvarArg.split('?');
    var flashVars = objectFromQueryString('&' + urlParts[1]);
    if(flvarArg.indexOf('record')>0) {
        //If there's a record, assume that we are using NFParser or Stitcher, so we need to escape the full url
        flashVars.nvml = escape(flvarArg);
    } else { 
        flashVars.nvml = urlParts[0];
    }
    flashVars.nv_bgimage = "http://www.nimblefish.com/img/loaderTurnUpVolume.jpg";
    var el = document.createElement('a');
    el.setAttribute('href', 'http://cdn.nimblefish.com/sr/external/nv/nvplayer.swf');
    hs.push(hs.anchors.htmls, el);
	hs.useBox = true;
	hs.width = (flashVars.hsWidth > 0 ? parseInt(flashVars.hsWidth) : 640);
    hs.height = (flashVars.hsHeight > 0 ? parseInt(flashVars.hsHeight) : 520);
    hs.swfOptions = {
        version:"9.0.28",
        expressInstallSwfurl: null,
        flashvars: flashVars,
        allowscriptaccess:"always",
        params:	{play:"true", loop:"false", menu:"false", quality:"high", allowscriptaccess:"always",bgcolor:"#ffffff",allowfullscreen:"true"},
        attributes:	{name:"movie", styleclass:"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000", align:"middle"}
    };//DO NOT ADD ID TO ATTRIBUTES!!!! THIS WILL BREAK HOW HIGHSLIDE CLEANS UP MEMORY
    hs.htmlExpand(el, { objectType: 'swf', objectWidth: (flashVars.obWidth > 0 ? flashVars.obWidth : 640), objectHeight: (flashVars.obHeight > 0 ? flashVars.obHeight : 480), maincontentText: ''});
}

function objectFromQueryString(s) {
    r = new Object();
    q = s;
    q = q.substring(1);
    if (q.length < 1) { return r; }
    while (q.indexOf('&') > -1) {
        p = q.substring(0,q.indexOf('&'));
        q = q.substring((q.indexOf('&')) + 1);
        n = p.substring(0,p.indexOf('='));
        v = p.substring((p.indexOf('=')) + 1);
        r[n] = unescape(v);
    }
    n = q.substring(0,q.indexOf('='));
    v = q.substring((q.indexOf('=')) + 1);
    r[n] = unescape(v);
    return r
}

//custom function to open sears advisor
function openSearsAdvisor(URL) {
	if ( window.open(URL) ) {
           return true;
      }
      return false;
}


