var paused;
function parseQuery(str) {
    var paramSplit = str.split("&");
    var map = new Object();
    
    for (var i = 0; i < paramSplit.length; i++) {
        var pair = paramSplit[i].split("=");
        
        map[pair[0]] = pair[1];
    }
    return map;
}
function resizePlayer(playerID, height) {
    try {
        var target = $('object#' + playerID);
    
        if (target.length == 0)
            target = $('object#myExperience');
    
        target.height(height);
    } catch (e) { }
}
function findlawVideoStart(params) {
    // params contains following properties
    //  id, name, shortDesc, longDesc
      if (!$("#videoTitleDescription"))
		return;
	paused=false;
	showTitleDesc();
	var html='<h3>'+params.name+'</h3><p>'+params.longDesc+'</p>';
	$("#videoTitleDescription").html(html);
}
function findlawVideoStop(params) {
    // params contains following properties
    //  id, name, shortDesc, longDesc
    paused=true;
    hideTitleDesc();
}
function findlawVideoChange(params) {
    // params contains following properties
    //  id, name, shortDesc, longDesc
}
$(document).ready(function(){
    $("object.findlawPlayer").each(function(){        
        if (jQuery.browser.msie)
            return;
            
        var swf = $(this).children("param[name='movie']").attr('value');
		
		//set domain name
		if (typeof fs3_inPublish != "undefined" && fs3_inPublish) {
			var domain=location.hostname;
			var port=location.port;
			if (port!="") {
				domain+=":"+port;
			}
			var flashVars=$(this).children("param[name='flashVars']");
			var mainDomain=getQueryParam(flashVars.attr('value'),"domainName");
			if (domain!=mainDomain) {
				var re=new RegExp(mainDomain, "g");
				flashVars.attr('value', flashVars.attr('value').replace(re, domain));
			}
		}
            
        $(this).removeAttr('classid');
        $(this).removeAttr('codebase');
        $(this).attr('type', "application/x-shockwave-flash");
        $(this).attr('data', swf);
        
        var newSwf = $(this).clone();
        $(this).replaceWith(newSwf);
    });
    
    $.extend($.tools.overlay.conf, { 
		start: { 
			absolute: true,
			top: null,
			left: null
		},
		
		fadeInSpeed: 'fast',
		zIndex: 9999
	});		
        
    $.tools.overlay.addEffect("myEffect", 
        function(onLoad) {
		
    		var overlay = this.getOverlay(),
    			 opts = this.getConf(),
    			 trigger = this.getTrigger(),
    			 self = this,
    			 oWidth = overlay.outerWidth({margin:true}),
    			 img = overlay.data("img");  
		
    		var contentWidth = overlay.width() + 70;
    		var contentHeight = overlay.height() + 70;
		
		
    		// growing image is required.
    		if (!img) { 
    			var bg = overlay.css("backgroundImage");
			
    			if (!bg) { 
    				throw "background-image CSS property not set for overlay"; 
    			}
			
    			// url("bg.jpg") --> bg.jpg
    			bg = bg.substring(bg.indexOf("(") + 1, bg.indexOf(")")).replace(/\"/g, "");
    			overlay.css("backgroundImage", "none");
			
    			img = $('<img src="' + bg + '"/>');
    			img.css({border:0,position:'absolute',display:'none'}).width(contentWidth).height(contentHeight);			
    			$('body').append(img); 
    			overlay.data("img", img);
    		}
		
    		// initial top & left
    		var w = $(window),
    			 itop = Math.round(w.height() / 2), 
    			 ileft = Math.round(w.width() / 2);
		
    		if (trigger) {
    			itop = trigger.position().top;
    			ileft = trigger.position().left;
    		} 
		
    		// adjust positioning relative toverlay scrolling position
            if (!opts.start.absolute) {
               itop += w.scrollTop();
               ileft += w.scrollLeft();
           }
		
    		// initialize background image and make it visible
    		img.css({
    			top: itop, 
    			left: ileft,
    			width: 0,
    			zIndex: opts.zIndex
    		}).show();
		
    		// begin growing
    		img.animate({
    			top: overlay.css("top"), 
    			left: overlay.css("left"), 
    			width: contentWidth, 
    			height: contentHeight}, opts.speed, function() { 
    			// set close button and content over the image
    			overlay.css("zIndex", opts.zIndex + 1).fadeIn(opts.fadeInSpeed, function()  { 
				
    				if (self.isOpened() && !$(this).index(overlay)) {					 
    					onLoad.call(); 
    				} else {
    					overlay.hide();	
    				} 
    			});
    		});
		
    	},
	    function(onClose) {
    		// variables
    		var overlay = this.getOverlay(), 
    			 opts = this.getConf(),
    			 trigger = this.getTrigger(),
    			 top,left;
		
		    // Stop video
		    if (overlay.children('object').length > 0 && overlay.children('object')[0].stopVideo)
		        overlay.children('object')[0].stopVideo();
		
    		// hide overlay & closers
    		overlay.hide();
		
    		// trigger position
    		if (trigger) {
    	        top = trigger.position().top;
    			left = trigger.position().left;
    		} 
		
    		// shrink image		
    		overlay.data("img").animate({top: top, left: left, width:0, height:0 }, opts.closeSpeed, onClose);	
	}
    );
    
     $("img[rel^='#'],a[rel^='#']").overlay({ 
         expose: { color: '#000', opacity: 0.5 }, 
         effect: 'myEffect'
     });
});
function hideTitleDesc() {
	if ($("#videoTitleDescription")) {		
		$("#videoTitleDescription").hide();
	}
}
function showTitleDesc() {
	if (!$("#videoTitleDescription"))
		return;
	if (!paused) {
		//get width from object.class and use it to set width of videoTitleDescription
		var findlawPlayer=$("object.findlawPlayer:eq(0)");
		if (findlawPlayer) {
			$("#videoTitleDescription").css("width",findlawPlayer.width());
		}
		$("#videoTitleDescription").show();
	}
}
function getQueryParam(query, param) {
	var re="[&]*"+param+"=([^&#]*)";
	var regex = new RegExp(re);
	var results = regex.exec(query);
 	return results==null?"":results[1];
}
   
  


