//jquery event drag

/*! Copyright (c) 2008, Three Dub Media (http://threedubmedia.com)  */
;(function($){ // secure $ jQuery alias
// jquery.event.drag.js - rev 14 - release 1.2
// Liscensed under the MIT License (MIT-LICENSE.txt)
// http://www.opensource.org/licenses/mit-license.php
// Created: 2008-06-04 | Updated: 2008-10-06
/*******************************************************************************************/
// Events: drag, dragstart, dragend
/*******************************************************************************************/

// jquery method
$.fn.drag = function( fn1, fn2, fn3 ){
	if ( fn2 ) this.bind('dragstart', fn1 ); // 2+ args
	if ( fn3 ) this.bind('dragend', fn3 ); // 3 args
	return !fn1 ? this.trigger('drag') // 0 args
		: this.bind('drag', fn2 ? fn2 : fn1 ); // 1+ args
	};

// local refs
var $event = $.event, $special = $event.special,

// special event configuration
drag = $special.drag = {
	not: ':input', // don't begin to drag on event.targets that match this selector
	distance: 0, // default distance dragged before dragstart
	setup: function( data ){
		data = $.extend({ distance: drag.distance, not: drag.not }, data || {});
		data.distance = squared( data.distance ); //  x² + y² = distance²
		$event.add( this, "mousedown", handler, data );
		},
	teardown: function(){
		$event.remove( this, "mousedown", handler );
		if ( this === drag.dragging ) drag.dragging = drag.proxy = null; // deactivate element
		selectable( this, true ); // enable text selection
		}
	};

// handle drag-releatd DOM events
function handler ( event ){ 
	var elem = this, returned, data = event.data || {};
	// mousemove or mouseup
	if ( elem === document ){ 
		// update event properties...
		event.dragTarget = elem = data.elem; // drag source element
		event.dragProxy = drag.proxy || elem; // proxy element or source
		event.cursorOffsetX = data.pageX - data.left; // mousedown offset
		event.cursorOffsetY = data.pageY - data.top; // mousedown offset
		event.offsetX = event.pageX - event.cursorOffsetX; // element offset
		event.offsetY = event.pageY - event.cursorOffsetY; // element offset
		}
	// mousedown, check some initial props to avoid the switch statement
	else if ( drag.dragging || event.which!=1 || $( event.target ).is( data.not ) ) return;
	// handle various events
	switch ( event.type ){
		// mousedown, left click, event.target is not restricted, init dragging
		case 'mousedown':
			$.extend( data, $( elem ).offset(), { 
				elem: elem, target: event.target,
				pageX: event.pageX, pageY: event.pageY
				}); // store some initial attributes
			$event.add( document, "mousemove mouseup", handler, data );
			selectable( elem, false ); // disable text selection
			return false; // prevents text selection in safari 
		// mousemove, check distance, start dragging
		case !drag.dragging && 'mousemove': 
			if ( squared( event.pageX-data.pageX ) 
				+ squared( event.pageY-data.pageY ) //  x² + y² = distance²
				< data.distance ) break; // distance tolerance not reached
			event.target = data.target; // force target from "mousedown" event (fix distance issue)
			returned = hijack( event, "dragstart", elem ); // trigger "dragstart", return proxy element
			if ( returned !== false ){ // "dragstart" not rejected
				drag.dragging = elem; // activate element
				drag.proxy = event.dragProxy = $( returned )[0] || elem; // set proxy
				}
		// mousemove, dragging
		case 'mousemove': 
			if ( drag.dragging ){
				returned = hijack( event, "drag", elem ); // trigger "drag"
				if ( $special.drop ){ // manage drop events
					$special.drop.allowed = ( returned !== false ); // prevent drop
					$special.drop.handler( event ); // "dropstart", "dropend"
					}
				if ( returned !== false ) break; // "drag" not rejected, stop		
				event.type = "mouseup"; // helps "drop" handler behave
				}
		// mouseup, stop dragging
		case 'mouseup': 
			$event.remove( document, "mousemove mouseup", handler ); // remove page events
			if ( drag.dragging ){
				if ( $special.drop ) $special.drop.handler( event ); // "drop"
				hijack( event, "dragend", elem ); // trigger "dragend"	
				}
			selectable( elem, true ); // enable text selection
			drag.dragging = drag.proxy = null; // deactivate element
			break;
		} 
	};
	
// set event type to custom value, and handle it
function hijack ( event, type, elem ){
	event.type = type; // force the event type
	return $event.handle.call( elem, event );
	};
	
// return the value squared	
function squared ( value ){ return Math.pow( value, 2 ); };
	
// toggles text selection attributes	
function selectable ( elem, bool ){ 
	if ( !elem ) return; // maybe element was removed ? 
	elem.unselectable = bool ? "off" : "on"; // IE
	elem.onselectstart = function(){ return bool; }; // IE
	if ( elem.style ) elem.style.MozUserSelect = bool ? "" : "none"; // FF
	};	
	
/*******************************************************************************************/
})( jQuery ); // confine scope
//jquery divdragndrop
jQuery.divDragnDrop = {
    
	currentDivColumn : null,
    
	dragObject: null,
	
	proxyObject:null,
    
	mouseOffset: null,
    
	lastY: 0,
	lastX: 0,
	
	columns:new Array(),
	
	cookieName:"dragndrop2",
	
	restore:function(){
		//Debugger.trace("restoring");
		var data = jQuery.cookiemanager.read(jQuery.divDragnDrop.cookieName);
		if(data==null)return;
		var rows;
		for(var obj in data){
			//Debugger.trace(obj+" "+data[obj]);
			column = $("#"+obj);
			
			rows=data[obj].split(",");
			for(var i=0;i<rows.length;i++){
				
					column.append($("#"+rows[i]));
				
			}
			
		}
		
	},
	
	reset:function()
	{
		jQuery.cookiemanager.deleteCookie(jQuery.divDragnDrop.cookieName);
	},
	
	save:function(){
		
		var rows ;
		var column=null;
		var columns=jQuery.divDragnDrop.columns;
		var data=new Object();
		var rows_array;
		var config;
		
		for(var i=0;i<columns.length;i++){
			column=$("#"+columns[i])[0];
			//Debugger.trace(column.id);
			rows_array=new Array();
			config = column.configuration;
			rows = jQuery("."+config.dragDivClass, column);
			for(var j=0;j<rows.length;j++){
				//Debugger.trace(rows[j]);
				rows_array.push(rows[j].id);
			}
			
			data[columns[i]]=rows_array.join(",");
		}
		
		jQuery.cookiemanager.write(jQuery.divDragnDrop.cookieName,data);
	},

    init: function(options) {
        // Set up the defaults if any
		
        this.each(function() { 
            this.configuration = jQuery.extend({
				proxyDragClass:"dragStart",
				nodropClass:"nodrop",
				dragDivClass:"draggableDiv",
				dragClass: "dragClass",
				dropClass: "dropClass",
				
				columns: null,
                scrollAmount: 5,
				dragHandle: null 
            }, options || {});
			
			//Debugger.trace(this.id);
			
			jQuery.divDragnDrop.columns.push(this.id);
			//Debugger.trace(jQuery.divDragnDrop.columns.length);
			jQuery.divDragnDrop.makeDraggable(this);
        });

        // Now we need to capture the mouse up and mouse move event
        // We can use bind so that we don't interfere with other event handlers
        jQuery(document)
            .bind('mousemove', jQuery.divDragnDrop.mousemove)
            .bind('mouseup', jQuery.divDragnDrop.mouseup);

        // Don't break the chain
        return this;
    },

    
    makeDraggable: function(div) {
		
        var config = div.configuration;
		
		var rows = jQuery("."+config.dragDivClass, div);
		
		rows.bind('dragstart',function( event ){
				
				
				//$(event.target).parent().addClass("dragStart");
				
				var parent = $(event.target);
				while(!parent.is('.'+config.dragHandle) && !parent.is('.'+config.dragDivClass))parent=parent.parent();
				if(parent.is('.'+config.dragDivClass))return false;
				
				jQuery.divDragnDrop.dragObject = this;
                jQuery.divDragnDrop.currentDivColumn = div;
                jQuery.divDragnDrop.mouseOffset = {x:event.cursorOffsetX,y:event.cursorOffsetY};
				
				jQuery.divDragnDrop.proxyObject= $( this ).clone().addClass(config.proxyDragClass)
                        .insertAfter( this );
				if(config.dropClass) {
					$( this ).addClass(config.dropClass);
					//$( this ).css({zIndex:100});
				}
				
				return jQuery.divDragnDrop.proxyObject;
                });
        rows.bind('drag',function( event ){
				//var parent=($(this).parent());
				
				 $( event.dragProxy ).css({
                        top: event.offsetY,
                        left: event.offsetX
                        });
						
				
                });
        rows.bind('dragend',function( event ){
			
			
				$( event.dragProxy ).remove();
				// $( this ).css('opacity',1)
				if(config.dropClass) $( this ).removeClass(config.dropClass);
				return;
                $( this ).animate({
                        top: event.offsetY,
                        left: event.offsetX,
                        opacity: 1
                        })
                });
		
	},

    /** Get the mouse coordinates from the event (allowing for browser differences) */
    mouseCoords: function(ev){
        if(ev.pageX || ev.pageY){
            return {x:ev.pageX, y:ev.pageY};
        }
        return {
            x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
            y:ev.clientY + document.body.scrollTop  - document.body.clientTop
        };
    },

    /** Given a target element and a mouse event, get the mouse offset from that element.
        To do this we need the element's position and the mouse position */
    getMouseOffset: function(target, ev) {
        ev = ev || window.event;

        var docPos    = this.getPosition(target);
        var mousePos  = this.mouseCoords(ev);
        return {x:mousePos.x - docPos.x, y:mousePos.y - docPos.y};
    },

    /** Get the position of an element by going up the DOM tree and adding up all the offsets */
    getPosition: function(e){
        var left = 0;
        var top  = 0;
        /** Safari fix -- thanks to Luis Chato for this! */
        if (e.offsetHeight == 0) {
            /** Safari 2 doesn't correctly grab the offsetTop of a table row
            this is detailed here:
            http://jacob.peargrove.com/blog/2006/technical/table-row-offsettop-bug-in-safari/
            the solution is likewise noted there, grab the offset of a table cell in the row - the firstChild.
            note that firefox will return a text node as a first child, so designing a more thorough
            solution may need to take that into account, for now this seems to work in firefox, safari, ie */
            e = e.firstChild; // a table cell
        }

        while (e.offsetParent){
            left += e.offsetLeft;
            top  += e.offsetTop;
            e     = e.offsetParent;
        }

        left += e.offsetLeft;
        top  += e.offsetTop;

        return {x:left, y:top};
    },

    mousemove: function(ev) {
		
		 if (jQuery.divDragnDrop.dragObject == null) {
            return;
        }
		
		
        var dragObj = jQuery(jQuery.divDragnDrop.dragObject);
        var config = jQuery.divDragnDrop.currentDivColumn.configuration;
        var mousePos = jQuery.divDragnDrop.mouseCoords(ev);
		
        var x = mousePos.x ;//+ jQuery.divDragnDrop.mouseOffset.x;
        var y = mousePos.y ;//+ jQuery.divDragnDrop.mouseOffset.y;
		//auto scroll the window
	    var yOffset = window.pageYOffset;
	 	if (document.all) {
	        // Windows version
	        //yOffset=document.body.scrollTop;
	        if (typeof document.compatMode != 'undefined' &&
	             document.compatMode != 'BackCompat') {
	           yOffset = document.documentElement.scrollTop;
	        }
	        else if (typeof document.body != 'undefined') {
	           yOffset=document.body.scrollTop;
	        }

	    }
		    
		if (mousePos.y-yOffset < config.scrollAmount) {
	    	window.scrollBy(0, -config.scrollAmount);
	    } else {
            var windowHeight = window.innerHeight ? window.innerHeight
                    : document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
            if (windowHeight-(mousePos.y-yOffset) < config.scrollAmount) {
                window.scrollBy(0, config.scrollAmount);
            }
        }


        if (y != jQuery.divDragnDrop.lastY || x!=jQuery.divDragnDrop.lastX) {
            // work out if we're going up or down...
            var movingDown = y > jQuery.divDragnDrop.lastY;
            // update the old value
            jQuery.divDragnDrop.lastY = y;
			
            // update the style to show we're dragging
			if (config.dragClass) {
				dragObj.addClass(config.dragClass);
			} 
			
            // If we're over a row then move the dragged row to there so that the user sees the
            // effect dynamically
			var oldColumn = jQuery.divDragnDrop.currentDivColumn;
			jQuery.divDragnDrop.findDropTargetColumn(dragObj, x,y);
			if(oldColumn !=jQuery.divDragnDrop.currentDivColumn){
				
				var currentRow = jQuery.divDragnDrop.findDropTargetRow(dragObj, y);
				
				if(currentRow){
					
					currentRow.parentNode.insertBefore(jQuery.divDragnDrop.proxyObject[0],currentRow.nextSibling);
					currentRow.parentNode.insertBefore(jQuery.divDragnDrop.dragObject, currentRow.nextSibling);
					
				}else{
					
					jQuery.divDragnDrop.currentDivColumn.insertBefore(jQuery.divDragnDrop.proxyObject[0],null);
					jQuery.divDragnDrop.currentDivColumn.insertBefore(jQuery.divDragnDrop.dragObject, null);
					
					
				}
				return;
				
			}
            var currentRow = jQuery.divDragnDrop.findDropTargetRow(dragObj, y);
			
			
			
            if (currentRow) {
                // TODO worry about what happens when there are multiple TBODIES
                if (movingDown && jQuery.divDragnDrop.dragObject != currentRow) {
                    jQuery.divDragnDrop.dragObject.parentNode.insertBefore(jQuery.divDragnDrop.dragObject, currentRow.nextSibling);
                } else if (! movingDown && jQuery.divDragnDrop.dragObject != currentRow) {
					try{
                    jQuery.divDragnDrop.dragObject.parentNode.insertBefore(jQuery.divDragnDrop.dragObject, currentRow);
					}catch(e){}
                }
            }
        }

        return false;
    },

   
    findDropTargetColumn: function(draggedRow, x, y) {
		
		var config = jQuery.divDragnDrop.currentDivColumn.configuration;
		var columns = config.columns;
		var scope = this;
		if(columns==null)return;
		
        for (var i=0; i<columns.length; i++) {
            var column = jQuery("#"+columns[i]);
			
			column.each(function() { 
				
				var columnPosition = scope.getPosition(this);
				
				if(x>columnPosition.x && y>columnPosition.y && x<(columnPosition.x+this.offsetWidth) && y<(columnPosition.y+this.offsetHeight)){
					
					jQuery.divDragnDrop.currentDivColumn = this;
					
				}
			});
			
        }
        return null;
    },
    findDropTargetRow: function(draggedRow, y) {
		
		var config = jQuery.divDragnDrop.currentDivColumn.configuration;
        var rows = jQuery("."+config.dragDivClass, jQuery.divDragnDrop.currentDivColumn);
		for (var i=0; i<rows.length; i++) {
            var row = rows[i];
			
			if(jQuery(row).hasClass(config.proxyDragClass))continue;
            var rowY    = this.getPosition(row).y;
            var rowHeight = parseInt(row.offsetHeight)/2;
            if (row.offsetHeight == 0) {
                rowY = this.getPosition(row.firstChild).y;
                rowHeight = parseInt(row.firstChild.offsetHeight)/2;
            }
            // Because we always have to insert before, we need to offset the height a bit
            if ((y > rowY - rowHeight) && (y < (rowY + rowHeight))) {
                // that's the row we're over
				// If it's the same as the current row, ignore it
				if (row == draggedRow) {return null;}
                var config = jQuery.divDragnDrop.currentDivColumn.configuration;
                if (config.onAllowDrop) {
                    if (config.onAllowDrop(draggedRow, row)) {
                        return row;
                    } else {
                        return null;
                    }
                } else {
					// If a row has nodrop class, then don't allow dropping (inspired by John Tarr and Famic)
                    var nodrop = jQuery(row).hasClass(config.nodropClass);
                    if (! nodrop) {
                        return row;
                    } else {
                        return null;
                    }
                }
                return row;
            }
        }
        return null;
    },

    mouseup: function(e) {
        if (jQuery.divDragnDrop.currentDivColumn && jQuery.divDragnDrop.dragObject) {
			
			
			var rows ;
			var column=null;
			var columns=jQuery.divDragnDrop.columns;
			
			var config;
			
			for(var i=0;i<columns.length;i++){
				column=$("#"+columns[i])[0];
				//Debugger.trace(column.id);
				
				config = column.configuration;
				
				rows = jQuery("."+config.dragDivClass, column);
				if(rows.length==0){
					//alert($(column).html());
					//alert(config.dragDivClass);
					$(column).append(jQuery.divDragnDrop.dragObject.nextSibling);
				}
			}
			
            var droppedRow = jQuery.divDragnDrop.dragObject;
            var config = jQuery.divDragnDrop.currentDivColumn.configuration;
            // If we have a dragObject, then we need to release it,
            // The row will already have been moved to the right place so we just reset stuff
			if (config.dragClass) {
	            jQuery(droppedRow).removeClass(config.dragClass);
			} 
            jQuery.divDragnDrop.dragObject   = null;
           
            jQuery.divDragnDrop.currentDivColumn = null; // let go of the table too
        }
		
    }
	

}

jQuery.fn.extend(
	{
		divDragnDrop : jQuery.divDragnDrop.init
	}
);
//featured menu
jQuery(document).ready(function(){
	$("#feature-index ul li a").hover(
		function(){
			
			var parent=$(this).parent();
			
			var htmlText=parent.children(".dataProvider").html();
			var fIndex=htmlText.indexOf("[CDATA[");
			
			if(fIndex<0)fIndex=0;
			else fIndex=fIndex+7;
			var lIndex=htmlText.indexOf("]]");
			if(lIndex>0)htmlText=htmlText.substring(fIndex,lIndex);
				
			parent=parent.parent().parent().parent().children("#featuredSelected");
			
			parent.html(htmlText);
			
		}, 
		function(){
			
		}
	);
});
//block UI plugin
/*
 * jQuery blockUI plugin
 * Version 2.04 (04/30/2008)
 * @requires jQuery v1.2.3 or later
 *
 * Examples at: http://malsup.com/jquery/block/
 * Copyright (c) 2007-2008 M. Alsup
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Thanks to Amir-Hossein Sobhi for some excellent contributions!
 */

(function($) {

if (/1\.(0|1|2)\.(0|1|2)/.test($.fn.jquery) || /^1.1/.test($.fn.jquery)) {
    alert('blockUI requires jQuery v1.2.3 or later!  You are using v' + $.fn.jquery);
    return;
}

// global $ methods for blocking/unblocking the entire page
$.blockUI   = function(opts) { install(window, opts); };
$.unblockUI = function(opts) { remove(window, opts); };

// plugin method for blocking element content
$.fn.block = function(opts) {
    return this.each(function() {
        if ($.css(this,'position') == 'static')
            this.style.position = 'relative';
        if ($.browser.msie) 
            this.style.zoom = 1; // force 'hasLayout'
        install(this, opts);
    });
};

// plugin method for unblocking element content
$.fn.unblock = function(opts) {
    return this.each(function() {
        remove(this, opts);
    });
};

$.blockUI.version = 2.04; // 2nd generation blocking at no extra cost!

// override these in your code to change the default behavior and style
$.blockUI.defaults = {
    // message displayed when blocking (use null for no message)
    message:  '<h1>Please wait...</h1>',
    
    // styles for the message when blocking; if you wish to disable
    // these and use an external stylesheet then do this in your code:
    // $.blockUI.defaults.css = {};
    css: { 
        padding:        0,
        margin:         0,
        width:          '30%', 
        top:            '40%', 
        left:           '35%', 
        textAlign:      'center', 
        color:          '#000', 
        border:         '3px solid #aaa',
        backgroundColor:'#fff',
        cursor:         'wait'
    },
    
    // styles for the overlay
    overlayCSS:  { 
        backgroundColor:'#000', 
        opacity:        '0.6' 
    },
    
    // z-index for the blocking overlay
    baseZ: 1000,
    
    // set these to true to have the message automatically centered
    centerX: true, // <-- only effects element blocking (page block controlled via css above)
    centerY: true,
    
    // allow body element to be stetched in ie6; this makes blocking look better
    // on "short" pages.  disable if you wish to prevent changes to the body height
    allowBodyStretch: true,
    
    // be default blockUI will supress tab navigation from leaving blocking content;
    constrainTabKey: true,
    
    // fadeOut time in millis; set to 0 to disable fadeout on unblock
    fadeOut:  400,
    
    // suppresses the use of overlay styles on FF/Linux (due to significant performance issues with opacity)
    applyPlatformOpacityRules: true
};

// private data and functions follow...

var ie6 = $.browser.msie && /MSIE 6.0/.test(navigator.userAgent);
var pageBlock = null;
var pageBlockEls = [];

function install(el, opts) {
    var full = (el == window);
    var msg = opts && opts.message !== undefined ? opts.message : undefined;
    opts = $.extend({}, $.blockUI.defaults, opts || {});
    opts.overlayCSS = $.extend({}, $.blockUI.defaults.overlayCSS, opts.overlayCSS || {});
    var css = $.extend({}, $.blockUI.defaults.css, opts.css || {});
    msg = msg === undefined ? opts.message : msg;

    // remove the current block (if there is one)
    if (full && pageBlock) 
        remove(window, {fadeOut:0}); 
    
    // if an existing element is being used as the blocking content then we capture
    // its current place in the DOM (and current display style) so we can restore
    // it when we unblock
    if (msg && typeof msg != 'string' && (msg.parentNode || msg.jquery)) {
        var node = msg.jquery ? msg[0] : msg;
        var data = {};
        $(el).data('blockUI.history', data);
        data.el = node;
        data.parent = node.parentNode;
        data.display = node.style.display;
        data.parent.removeChild(node);
    }
    
    var z = opts.baseZ;
    
    // blockUI uses 3 layers for blocking, for simplicity they are all used on every platform;
    // layer1 is the iframe layer which is used to supress bleed through of underlying content
    // layer2 is the overlay layer which has opacity and a wait cursor
    // layer3 is the message content that is displayed while blocking
    
    var lyr1 = ($.browser.msie) ? $('<iframe class="blockUI" style="z-index:'+ z++ +';border:none;margin:0;padding:0;position:absolute;width:100%;height:100%;top:0;left:0" src="javascript:false;"></iframe>')
                                : $('<div class="blockUI" style="display:none"></div>');
    var lyr2 = $('<div class="blockUI" style="z-index:'+ z++ +';cursor:wait;border:none;margin:0;padding:0;width:100%;height:100%;top:0;left:0"></div>');
    var lyr3 = full ? $('<div class="blockUI blockMsg blockPage" style="z-index:'+z+';position:fixed"></div>')
                    : $('<div class="blockUI blockMsg blockElement" style="z-index:'+z+';display:none;position:absolute"></div>');

    // if we have a message, style it
    if (msg) 
        lyr3.css(css);

    // style the overlay
    if (!opts.applyPlatformOpacityRules || !($.browser.mozilla && /Linux/.test(navigator.platform))) 
        lyr2.css(opts.overlayCSS);
    lyr2.css('position', full ? 'fixed' : 'absolute');
    
    // make iframe layer transparent in IE
    if ($.browser.msie) 
        lyr1.css('opacity','0.0');

    $([lyr1[0],lyr2[0],lyr3[0]]).appendTo(full ? 'body' : el);
    
    // ie7 must use absolute positioning in quirks mode and to account for activex issues (when scrolling)
    var expr = $.browser.msie && (!$.boxModel || $('object,embed', full ? null : el).length > 0);
    if (ie6 || expr) {
        // give body 100% height
        if (full && opts.allowBodyStretch && $.boxModel)
            $('html,body').css('height','100%');

        // fix ie6 issue when blocked element has a border width
        if ((ie6 || !$.boxModel) && !full) {
            var t = sz(el,'borderTopWidth'), l = sz(el,'borderLeftWidth');
            var fixT = t ? '(0 - '+t+')' : 0;
            var fixL = l ? '(0 - '+l+')' : 0;
        }

        // simulate fixed position
        $.each([lyr1,lyr2,lyr3], function(i,o) {
            var s = o[0].style;
            s.position = 'absolute';
            if (i < 2) {
                full ? s.setExpression('height','document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + "px"')
                     : s.setExpression('height','this.parentNode.offsetHeight + "px"');
                full ? s.setExpression('width','jQuery.boxModel && document.documentElement.clientWidth || document.body.clientWidth + "px"')
                     : s.setExpression('width','this.parentNode.offsetWidth + "px"');
                if (fixL) s.setExpression('left', fixL);
                if (fixT) s.setExpression('top', fixT);
            }
            else if (opts.centerY) {
                if (full) s.setExpression('top','(document.documentElement.clientHeight || document.body.clientHeight) / 2 - (this.offsetHeight / 2) + (blah = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + "px"');
                s.marginTop = 0;
            }
        });
    }
    
    // show the message
    lyr3.append(msg).show();
    if (msg && (msg.jquery || msg.nodeType))
        $(msg).show();

    // bind key and mouse events
    bind(1, el, opts);
        
    if (full) {
        pageBlock = lyr3[0];
        pageBlockEls = $(':input:enabled:visible',pageBlock);
        setTimeout(focus, 20);
    }
    else
        center(lyr3[0], opts.centerX, opts.centerY);
};

// remove the block
function remove(el, opts) {
    var full = el == window;
    var data = $(el).data('blockUI.history');
    opts = $.extend(true, {}, $.blockUI.defaults, opts);
    bind(0, el, opts); // unbind events
    var els = full ? $('body > .blockUI') : $('.blockUI', el);
    if (full) 
        pageBlock = pageBlockEls = null;

    if (opts.fadeOut) {
        els.fadeOut(opts.fadeOut);
        setTimeout(function() { reset(els,data); }, opts.fadeOut);
    }
    else
        reset(els, data);
};

// move blocking element back into the DOM where it started
function reset(els,data) {
    els.each(function(i,o) {
        // remove via DOM calls so we don't lose event handlers
        if (this.parentNode) 
            this.parentNode.removeChild(this);
    });
    if (data && data.el) {
        data.el.style.display = data.display;
        data.parent.appendChild(data.el);
        $(data.el).removeData('blockUI.history');
    }
};

// bind/unbind the handler
function bind(b, el, opts) {
    var full = el == window, $el = $(el);
    
    // don't bother unbinding if there is nothing to unbind
    if (!b && (full && !pageBlock || !full && !$el.data('blockUI.isBlocked'))) 
        return;
    if (!full) 
        $el.data('blockUI.isBlocked', b);
        
    // bind anchors and inputs for mouse and key events
    var events = 'mousedown mouseup keydown keypress click';
    b ? $(document).bind(events, opts, handler) : $(document).unbind(events, handler);

// former impl...
//    var $e = $('a,:input');
//    b ? $e.bind(events, opts, handler) : $e.unbind(events, handler);
};

// event handler to suppress keyboard/mouse events when blocking
function handler(e) {
    // allow tab navigation (conditionally)
    if (e.keyCode && e.keyCode == 9) {
        if (pageBlock && e.data.constrainTabKey) {
            var els = pageBlockEls;
            var fwd = !e.shiftKey && e.target == els[els.length-1];
            var back = e.shiftKey && e.target == els[0];
            if (fwd || back) {
                setTimeout(function(){focus(back)},10);
                return false;
            }
        }
    }
    // allow events within the message content
    if ($(e.target).parents('div.blockMsg').length > 0)
        return true;
        
    // allow events for content that is not being blocked
    return $(e.target).parents().children().filter('div.blockUI').length == 0;
};

function focus(back) {
    if (!pageBlockEls) 
        return;
    var e = pageBlockEls[back===true ? pageBlockEls.length-1 : 0];
    if (e) 
        e.focus();
};

function center(el, x, y) {
    var p = el.parentNode, s = el.style;
    var l = ((p.offsetWidth - el.offsetWidth)/2) - sz(p,'borderLeftWidth');
    var t = ((p.offsetHeight - el.offsetHeight)/2) - sz(p,'borderTopWidth');
    if (x) s.left = l > 0 ? (l+'px') : '0';
    if (y) s.top  = t > 0 ? (t+'px') : '0';
};

function sz(el, p) { 
    return parseInt($.css(el,p))||0; 
};

})(jQuery);
//jquery cookie
/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

/**
 * Create a cookie with the given name and value and other optional parameters.
 *
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 * @desc Create a cookie with all available options.
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 * @example $.cookie('the_cookie', null);
 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
 *       used when the cookie was set.
 *
 * @param String name The name of the cookie.
 * @param String value The value of the cookie.
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
 *                             when the the browser exits.
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
 *                        require a secure protocol (like HTTPS).
 * @type undefined
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
		document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
//jquery addnremove

jQuery.addnremove = {
	
    items:new Array(),
	
	cookieName:"addnremove",
	
	restore:function()
	{
		var data = jQuery.cookiemanager.read(jQuery.addnremove.cookieName);
		if(data==null)return;
		items=new Array();
		var item;
		for(var obj in data){
			//Debugger.trace(obj+" "+data[obj]);
			items.push(obj);
			jQuery.addnremove.setIndex(obj,data[obj]);
		}
		jQuery.addnremove.items=items;
	},
	
	reset:function()
	{
		jQuery.cookiemanager.deleteCookie(jQuery.addnremove.cookieName);
	},
	
	save:function()
	{
		//alert("saving");
		
		var items=jQuery.addnremove.items;
		var data=new Object();
		
		var item;
		var config;
		
		for(var i=0;i<items.length;i++){
			//alert("items[i]: "+items[i]);
			item=$("#"+items[i])[0];
			
			//alert(item.id);
			config = item.configuration;
			//alert(item.id+" "+config.index);
			if(item.id!="")data[items[i]]=config.index;
		}
		
		jQuery.cookiemanager.write(jQuery.addnremove.cookieName,data);
	},
	
    init: function(options) {
        
        this.each(function() { 
            this.configuration = jQuery.extend({
				addClass:"module-add",
				removeClass:"module-remove",
				contentClass:"module-content",
				addnremovePointer:"addnremovePointer",
				index:null
            }, options || {});
			
			if(jQuery.addnremove.initialize(this))jQuery.addnremove.items.push(this.id);
			//alert(jQuery.addnremove.items);
        });

        
        return this;
    },

    
    initialize: function(container) {
		
		var config=container.configuration;
		var addbtn=jQuery("."+config.addClass,container);
		var contentObject=jQuery("."+config.contentClass,container);
		var elements=jQuery("."+config.addnremovePointer,contentObject[0]);
		config.index=0;
		for(var i=0;i<elements.length;i++){
			if($(elements[i]).css("display")=="none")break;
		}
		config.index=i;
		
		
		if(addbtn.length==1){
			addbtn.click(function(){
							jQuery.addnremove.addLastElement(container,true);
						});
		}else{
			return false;
		}
		
		var rembtn=jQuery("."+config.removeClass,container);
		if(rembtn.length==1){
			rembtn.click(function(){
							jQuery.addnremove.removeLastElement(container,true);
						});
		}else{
			return false;
		}
		return true;
		
    },
	
	addLastElement: function(container,bAnim){
		//alert("addLastElement");
		var config=container.configuration;
		var contentObject=jQuery("."+config.contentClass,container);
		
		if(contentObject.length!=1)return;
		var elements=jQuery("."+config.addnremovePointer,contentObject[0]);
		
		if(config.index==null){
			config.index=elements.length;
			return;
		}
		
		if(config.index>=elements.length){
			config.index=elements.length;
			return;
		}
		
		
		
		if(bAnim)$( elements[config.index] ).slideDown();
		else $( elements[config.index] ).css({display:"block"});
		config.index++;
	},
	
	removeLastElement: function(container,bAnim){
		var config=container.configuration;
		var contentObject=jQuery("."+config.contentClass,container);
		if(contentObject.length!=1)return;
		var elements=jQuery("."+config.addnremovePointer,contentObject[0]);
		
		if(config.index==null){
			config.index=elements.length;
		}
		config.index--;
		if(config.index<0){
			config.index=0;
			return;
		}
		
		if(bAnim) $( elements[config.index] ).slideUp();
		else $( elements[config.index] ).css({display:"none"});
	},
	
	setIndex: function(id,index){
		index=parseInt(index);
		var obj=$("#"+id)[0];
		var currentIndex=obj.configuration.index;
		if(currentIndex!=index){
			if(currentIndex<index){
				while(currentIndex<index){
					jQuery.addnremove.addLastElement(obj,false);
					currentIndex++;
				}
			}else{
				while(currentIndex>index){
					jQuery.addnremove.removeLastElement(obj,false);
					currentIndex--;
				}
			}
		}
		
	}

	

}

jQuery.fn.extend(
	{
		addnremove : jQuery.addnremove.init
	}

);
//jquery collpase manager
jQuery.collapsemanager = {
	cookieName:"collapse_items1",
	className:null,
    save: function() {
		var className=jQuery.collapsemanager.className;
		var data=new Object();
		$('.'+className).each(function(){
				
				var parent_id = $(this).parents('.module').attr('id');
				var displayState=$(this).parents('.module').children('.module-toggle').css('display');
				
				if(displayState!=undefined)data[parent_id]=displayState;
			});
			
		jQuery.cookiemanager.write(jQuery.collapsemanager.cookieName,data);
    },

    
	reset:function()
	{
		jQuery.cookiemanager.deleteCookie(jQuery.collapsemanager.cookieName);
	},
	
    restore: function() {
		
		var data=jQuery.cookiemanager.read(jQuery.collapsemanager.cookieName);
		
		if(data==null)return;
		for(var obj in data){
			try{
			$("#"+obj).children('.module-toggle').css('display',data[obj]);
			}catch(e){
			}
		}
		
		
    },
	
	initialize:function(className){
		
		jQuery.collapsemanager.className=className;
		$('.'+className).click(function(){
			linktoggle = $(this);
			
			// let's toggle the box
			$(this).parents('.module').children('.module-toggle').slideToggle('fast');
			
			return false;
			
		});
	}

	

}
//jquery cookie manager
jQuery.cookiemanager = {
	
    read: function(name) {
		
		
        var str = ($.cookie(name));
		//alert("r: "+name);
		//alert("r: "+str);
		if(str==null)return null;
		
		var data=new Object();
		var str_array=str.split(";");
		var aux;
		for(var i=0;i<str_array.length-1;i++){
			aux=str_array[i].split("=");
			data[aux[0]]=aux[1];
		}
		return data;
    },

    
    write: function(name,data,exp) {
		var str="";
		
		for(var obj in data){
			
			str+=obj+"="+data[obj]+";";
		}
		//alert("w: "+name);
		//alert("w: "+str);
		
		$.cookie(name,str,{expires:2});
		
    },
	
	deleteCookie: function(name){
		//alert("d:"+name);
		$.cookie(name,"",{expires:-1});
	}

	

}

jQuery.extend(
	{
		read : jQuery.cookiemanager.read,
		write : jQuery.cookiemanager.write,
		deleteCookie : jQuery.cookiemanager.deleteCookie
		
	}

);
//jquery customize manager

jQuery.customizemanager = {
    
	cookieName:"customizemanager1",
	custommanagers:new Array(),
	
	restore:function(){
		//Debugger.trace("restoring");
		var data = jQuery.cookiemanager.read(jQuery.customizemanager.cookieName);
		if(data==null)return;
		var custommanager;
		var config;
		for(var obj in data){
			custommanager=$("#"+obj)[0];
			config=custommanager.configuration;
			items=data[obj].split(",");
			for(var i=0;i<items.length;i++){
					var item=items[i].split("|");
					var itemID=item[0];
					var itemDisplay=item[1];
					$("#"+itemID).css({display:itemDisplay});
					$("#"+itemID+config.ID_EXT).attr({checked:(itemDisplay!="none")});
				
			}
			
		}
		
		
	},
	
	reset:function()
	{
		//alert(jQuery.customizemanager.cookieName);
		jQuery.cookiemanager.deleteCookie(jQuery.customizemanager.cookieName);
	},
	
	save:function(){
		var items ;
		var custommanagers=jQuery.customizemanager.custommanagers;
		var data=new Object();
		var data_array;
		var config;
		var custommanager;
		
		for(var i=0;i<custommanagers.length;i++){
			custommanager=$("#"+custommanagers[i])[0];
			//Debugger.trace(column.id);
			data_array=new Array();
			config = custommanager.configuration;
			items = config.items;
			for(var j=0;j<items.length;j++){
				
				data_array.push(items[j]+"|"+$("#"+items[j]).css("display"));
			}
			//alert(data_array);
			
			data[custommanagers[i]]=data_array.join(",");
		}
		
		jQuery.cookiemanager.write(jQuery.customizemanager.cookieName,data);
	},

    init: function(options) {
        // Set up the defaults if any
		
        this.each(function() { 
            this.configuration = jQuery.extend({
				togglebtnID:"customize",
				items:null,
				rootClass:"module",
				ulContainerID:"choicesContainer",
				liClass:"active",
				titleElement:"h3",
				closeItemClass:"module-close",
				closeBtnID:"",
				ID_EXT:"__li",
				formID:""
            }, options || {});
			jQuery.customizemanager.custommanagers.push(this.id);
			jQuery.customizemanager.initialize(this);
        });

        return this;
    },
	
	initialize:function(obj){
		var config = obj.configuration;
		$('#'+config.togglebtnID).click(function(){
			if(config.formID!=""){
				$('#'+config.formID).slideToggle('fast');
				return false;
			}
			$('#'+obj.id+' form').slideToggle('fast');
			return false;

		});
		
		$('#'+config.closeBtnID).click(function(){
			if(config.formID!=""){
				$('#'+config.formID).slideUp('fast');
				return false
			}
			$('#'+obj.id+' form').slideUp('fast');
			return false;

		});
		
		var items=config.items;
		var closeItemClass=config.closeItemClass;
		if(items==null)return;
		
		var closebtn;
		var listHTML="";
		/*
		<li class="active">
            <input checked="checked" name="panels[sport]" id="sport" type="checkbox" />
            <label>Em Foco</label>
          </li>
		 */ 
		
		for(var i=0;i<items.length;i++){
			var itemObj=$("#"+items[i]);
			closebtn=$("."+closeItemClass,itemObj[0]);
			var title=$(config.titleElement,itemObj[0]);
			//if we have html tags remove them and get the first value
			title=(title).html().split("<")[0];
			if(closebtn.length!=0){
				closebtn.click(function(){
					$(this).parents('.'+config.rootClass).css({display:"none"});
					$("#"+$(this).parents('.'+config.rootClass)[0].id+config.ID_EXT)[0].checked=false;
					
				});
			}
			listHTML+="<li class=\""+config.liClass+"\"><input checked=\"checked\" id=\""+items[i]+config.ID_EXT+"\" type=\"checkbox\">"+title+"</checkbox></li>";
			
		}
		
		$("#"+config.ulContainerID).html(listHTML);
		for(var i=0;i<items.length;i++){
			$("#"+items[i]+config.ID_EXT).click(function(){
					var targetID=this.id.split(config.ID_EXT)[0];
					var target_jq=$("#"+targetID);
					if(this.checked){
						target_jq.css({display:"block"});
					}else{
						target_jq.css({display:"none"});
					}
				});
		}
		
		
	}
}

jQuery.fn.extend(
	{
		customizemanager : jQuery.customizemanager.init
	}
);

//jquery radiobutton

jQuery.radiobuttonmanager = {
    
	cookieName:"radiobuttonmanager1",
	managers:new Array(),
	
	restore:function(){
		
		var data = jQuery.cookiemanager.read(jQuery.radiobuttonmanager.cookieName);
		if(data==null)return;
		var manager;
		var config;
		for(var obj in data){
			manager=$("#"+obj)[0];
			config=manager.configuration;
			config.selectedID=data[obj];
			
			//check if the flash is ready
			/*if (navigator.appName.indexOf("Microsoft") != -1) {
				if(window[config.flashID]==undefined || window[config.flashID].setDataIdentifier==undefined){
					setTimeout(jQuery.radiobuttonmanager.restore,1000);
					return;
				}
			}
			else {
				if(document[config.flashID]==undefined || document[config.flashID].setDataIdentifier==undefined){
					setTimeout(jQuery.radiobuttonmanager.restore,1000);
					return;
				}
			}*/
			
			
			
			
			
			
			var j_rb=$('#'+data[obj],manager);
			j_rb.attr({checked:true});
			//no need to change the top title.
			//$("#"+config.flashTitleID).html(j_rb.attr("value").split("|")[0]);
			
			/*if (navigator.appName.indexOf("Microsoft") != -1) {
					
						window[config.flashID].setDataIdentifier($("#"+config.selectedID).attr("value"));
				   }
				   else {
					 var res=document[config.flashID].setDataIdentifier($("#"+config.selectedID).attr("value"));
					  
					  if(res==undefined){
						  //fix safari issue
						  setTimeout(jQuery.radiobuttonmanager.restore,1000);
						  return;
					  }
						  
				   }*/
				   
		
		}
		
	},
	
	getSelectedRadiobuttonFor:function(containerID)
	{
		var manager=$("#"+containerID)[0];
		var	config=manager.configuration;
		return $("#"+config.selectedID).attr("value");
		
	},
	
	reset:function()
	{
		
		jQuery.cookiemanager.deleteCookie(jQuery.radiobuttonmanager.cookieName);
	},
	
	save:function(){
		
		var managers=jQuery.radiobuttonmanager.managers;
		var data=new Object();
		var config;
		var manager;
		
		for(var i=0;i<managers.length;i++){
			
			manager=$("#"+managers[i])[0];
			config = manager.configuration;
			//alert(config.selectedID);
			
			data[managers[i]]=config.selectedID;
			
			
		}
		
		jQuery.cookiemanager.write(jQuery.radiobuttonmanager.cookieName,data);
		
	},

    init: function(options) {
        // Set up the defaults if any
		
        this.each(function() { 
            this.configuration = jQuery.extend({
				rbClass:"radiobutton",
				rbName:"group_rb1",
				flashID:"topTicker1",
				flashTitleID:"bolsaTitle1",
				selectedID:"rb1"
            }, options || {});
			jQuery.radiobuttonmanager.managers.push(this.id);
			jQuery.radiobuttonmanager.initialize(this);
        });
		
		
        return this;
    },
	
	initialize:function(obj){
		
		var config = obj.configuration;
		
		$("input[@name='"+config.rbName+"']").change(

			function()

			{
				//alert("change");
				if ($("input[@name='"+config.rbName+"']:checked").val()){

					//alert(this.value);
					//$("#"+config.flashTitleID).html(this.value.split("|")[0]);
					if (navigator.appName.indexOf("Microsoft") != -1) {
					//alert(window[obj.configuration.flashID]);
						window[obj.configuration.flashID].setTitle(this.value.split("|")[0]);
						window[obj.configuration.flashID].setDataIdentifier(this.value.split("|")[1]);
				   }
				   else {
					   document[obj.configuration.flashID].setTitle(this.value.split("|")[0]);
					  document[obj.configuration.flashID].setDataIdentifier(this.value.split("|")[1]);
				   }
				   //alert(this.id);
				   obj.configuration.selectedID=this.id;
				}
				$(this).blur();

			}

		);

		
		
	}
}

jQuery.fn.extend(
	{
		radiobuttonmanager : jQuery.radiobuttonmanager.init
	}
);

//jquery exit manager

jQuery.exitmanager = {
	resetFlag:false,
    onExit: function() {
		if(!jQuery.exitmanager.resetFlag){
			
			//alert("saving");
			
			jQuery.addnremove.save();jQuery.collapsemanager.save();jQuery.divDragnDrop.save();jQuery.customizemanager.save();
			jQuery.radiobuttonmanager.save();
			
		}else{
			//alert("not saving");
		}
		
    }
}

jQuery.extend(
	{
		read : jQuery.exitmanager.onExit
	}

);
//reset.js
$(document).ready(function(){	
	$('#reset').click(function(){

		$.blockUI(
			{ 
				message: $('#dialog-form'), 
				overlayCSS:  {  
			        backgroundColor:'#000',  
			        opacity:        '0.7'  
			    }
		
			
		});
	
		return false;

	})

	$('#dialog-form #cancel-reset').click(function(){
		$.unblockUI();
	});	
	$('#dialog-form #reset-confirm').click(function(){
		$.unblockUI();
		$.addnremove.reset();
		jQuery.collapsemanager.reset();
		jQuery.divDragnDrop.reset();
		jQuery.customizemanager.reset();
		jQuery.radiobuttonmanager.reset();
		
		//flash resets
		if (navigator.appName.indexOf("Microsoft") != -1) {
			//alert(window["topTicker1"].resetCookie);
			window["topTicker1"].resetCookie();
			window["topTicker2"].resetCookie();
		}
		else {
			//alert(document["topTicker1"].resetCookie);
			document["topTicker1"].resetCookie();
			document["topTicker2"].resetCookie();
			
		}
	
		
		
		jQuery.exitmanager.resetFlag=true;
		window.location.reload( false );
		//$.addnremove.restore();jQuery.collapsemanager.restore();jQuery.divDragnDrop.restore();
	});
});
//end reset.js
//dragger container //
jQuery(document).ready(function(){
	$("#draggerContainer .draggableDiv").draggable({ handle: ".dragHandle" });

});

//VIDEO PLAYER
/*
 * simplyScroll 1.0.3 - a scroll-tastic jQuery plugin
 *
 * http://logicbox.net/jquery/simplyscroll
 * Last revised: 21/02/2009 00:34
 *
 */

(function($){$.fn.simplyScroll=function(o){return this.each(function(){new $.simplyScroll(this,o);});};var defaults={className:'simply-scroll',frameRate:24,speed:1,horizontal:true,autoMode:'off',loopOverload:0,pauseOnHover:true,localJsonSource:'',flickrFeed:'',jsonImgWidth:240,jsonImgHeight:180};$.simplyScroll=function(el,o){var self=this;this.o=$.extend({},defaults,o||{});this.auto=this.o.autoMode!=="off"?true:false;this.$list=$(el);this.$list.addClass('simply-scroll-list').wrap('<div class="simply-scroll-clip"></div>').parent().wrap('<div class="'+this.o.className+' simply-scroll-container"></div>');if(!this.o.auto){this.$list.parent().parent().prepend('<div class="simply-scroll-forward"></div>').prepend('<div class="simply-scroll-back"></div>');}
if(this.o.flickrFeed){$.getJSON(this.o.flickrFeed+"&format=json&jsoncallback=?",function(data){json=[];$.each(data.items,function(i,item){json.push({"src":item.media.m,"title":item.title,"link":item.link});});self.renderData(json);});}else if(this.o.localJsonSource){$.getJSON(this.o.localJsonSource,function(json){self.renderData(json);});}else{$(window).load(function(){self.init();});}};$.simplyScroll.fn=$.simplyScroll.prototype={};$.simplyScroll.fn.extend=$.simplyScroll.extend=$.extend;$.simplyScroll.fn.extend({init:function(){this.$items=this.$list.children();this.$clip=this.$list.parent();this.$container=this.$clip.parent();if(!this.o.horizontal){this.itemMax=this.$items.eq(0).height();this.clipMax=this.$clip.height();this.dimension='height';this.moveBackClass='simply-scroll-btn-up';this.moveForwardClass='simply-scroll-btn-down';}else{this.itemMax=this.$items.eq(0).width();this.clipMax=this.$clip.width();this.dimension='width';this.moveBackClass='simply-scroll-btn-left';this.moveForwardClass='simply-scroll-btn-right';}
this.posMin=0;this.posMax=this.$items.length*this.itemMax;this.$list.css(this.dimension,this.posMax+'px');if(this.o.autoMode=='loop'){var addItems=Math.ceil(this.clipMax/this.itemMax)+this.o.loopOverload;this.$items.slice(0,addItems).clone(true).appendTo(this.$list);this.posMax+=(this.clipMax-this.o.speed);this.$list.css(this.dimension,this.posMax+(this.itemMax*addItems)+'px');}
this.interval=null;this.intervalDelay=Math.floor(1000/this.o.frameRate);while(this.itemMax%this.o.speed!==0){this.o.speed--;if(this.o.speed===0){this.o.speed=1;break;}}
var self=this;this.trigger=null;this.funcMoveBack=function(){self.trigger=this;self.moveBack();};this.funcMoveForward=function(){self.trigger=this;self.moveForward();};this.funcMoveStop=function(){self.moveStop();};this.funcMoveResume=function(){self.moveResume();};if(this.auto){if(this.o.pauseOnHover){this.$clip.hover(this.funcMoveStop,this.funcMoveResume);}
this.moveForward();}else{this.$btnBack=$('.simply-scroll-back',this.$container).addClass('simply-scroll-btn'+' '+this.moveBackClass+' '+'disabled').hover(this.funcMoveBack,this.funcMoveStop);this.$btnForward=$('.simply-scroll-forward',this.$container).addClass('simply-scroll-btn'+' '+this.moveForwardClass).hover(this.funcMoveForward,this.funcMoveStop);}},moveForward:function(){var self=this;this.movement='forward';if(this.trigger!==null){this.$btnBack.removeClass('disabled');}
self.interval=setInterval(function(){if(!self.o.horizontal&&self.$clip[0].scrollTop<(self.posMax-self.clipMax)){self.$clip[0].scrollTop+=self.o.speed;}else if(self.o.horizontal&&self.$clip[0].scrollLeft<(self.posMax-self.clipMax)){self.$clip[0].scrollLeft+=self.o.speed;}else if(self.o.autoMode=='loop'){self.resetPos();}else{self.moveStop(self.movement);}},self.intervalDelay);},moveBack:function(){var self=this;this.movement='back';if(this.trigger!==null){this.$btnForward.removeClass('disabled');}
self.interval=setInterval(function(){if(!self.o.horizontal&&self.$clip[0].scrollTop>0){self.$clip[0].scrollTop-=self.o.speed;}else if(self.o.horizontal&&self.$clip[0].scrollLeft>0){self.$clip[0].scrollLeft-=self.o.speed;}else if(self.o.autoMode=='loop'){self.resetPos();}else{self.moveStop(self.movement);}},self.intervalDelay);},moveStop:function(moveDir){clearInterval(this.interval);if(this.trigger!==null){if(typeof moveDir!="undefined"){$(this.trigger).addClass('disabled');}
this.trigger=null;}
if(this.auto){if(this.o.autoMode=='bounce'){moveDir=='forward'?this.moveBack():this.moveForward();}}},moveResume:function(){this.movement=='forward'?this.moveForward():this.moveBack();},resetPos:function(){if(!this.o.horizontal){this.$clip[0].scrollTop=0;}else{this.$clip[0].scrollLeft=0;}},renderData:function(json){if(json.length>0){var self=this;$.each(json,function(i,item){$("<img/>").attr({src:item.src,title:item.title,alt:item.title,width:self.o.jsonImgWidth,height:self.o.jsonImgHeight}).appendTo(self.$list);});this.init();}}});})(jQuery);

//start custom player code //
(function($) {
	$(function() { //on DOM ready
		$("#videosScroller").simplyScroll({
			className: 'vert',
			horizontal: false,
			frameRate: 20,
			speed: 20
		});
	});
})(jQuery);

function isIE() {
  return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
}
	
function clickVideo(video){
  var o = document.getElementById("videos_object");
  var c = document.getElementById("videos_content");
	if (!o) {
		var d = document.createElement("div");
		d.setAttribute("id", "videos_object");
		c.insertBefore(d,c.firstChild);
	}
	
  document.getElementById('videos_list').style.display = 'none';
  document.getElementById('videos_content').style.display = 'block';
  
  var flashvars = {};
  flashvars.file = video+'/mov/1';
  var params = {};
  params.allowscriptaccess = "always";
  params.allowfullscreen = "true";
  var attributes = {};
  attributes.id = "videos_object";
  swfobject.embedSWF("http://imgs.sapo.pt/sapovideo/swf/flvplayer.swf", "videos_object", "302", "276", "7.0.0", false, flashvars, params, attributes);
}

function onClipDone(clip) {
		document.getElementById('videos_content').style.display = 'none';
		document.getElementById('videos_list').style.display = 'block';
		swfobject.removeSWF('videos_object');
}

function clickVideoLive(){
  document.getElementById('videos_list').style.display = 'none';
  document.getElementById('videos_content_live').style.display = 'block';
  var content = document.getElementById('videos_object_live');
  if(isIE()) {
    content.innerHTML = "<object id=\"videos_content_live_media\" width=\"302\" height=\"215\" classid=\"CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95\" type=\"application/x-oleobject\"><param name=\"FileName\" value=\"mms://espalhabrasas.sapo.pt/tvde\" /><param name=\"autostart\" value=\"true\" /><param name=\"showcontrols\" value=\"true\" /><param name=\"showstatusBar\" value=\"false\" /><param name=\"showdisplay\" value=\"false\" /></object>";
  }else{
    content.innerHTML = "<embed id=\"videos_content_live_media\" width=\"302\" height=\"235\" pluginspace=\"http://www.microsoft.com/Windows/MediaPlayer/\" type=\"application/x-mplayer2\" src=\"mms://espalhabrasas.sapo.pt/tvde\" autostart=\"true\" showcontrols=\"true\" showstatusBar=\"false\" showdisplay=\"false\" showstatusBar=\"false\" type=\"application/x-mplayer2\" />";
  }
}

function onClipDoneLive() {
		document.getElementById('videos_content_live').style.display = 'none';
    var content = document.getElementById('videos_object_live');
		if(isIE()) {
		  var media = document.getElementById('videos_content_live_media');
			media.Stop();
			media.parentNode.removeChild(media); 
		}else{
		  content.innerHTML = 's';
		}
		document.getElementById('videos_list').style.display = 'block';
}

//end custom player code //


//END VIDEO PLAYER