/**
 * Rollover effect, changes element's src attribute on hover, e.g.:
 *
 * image.png?foo=bar => image_h.png?foo=bar
 *
 * Pass true to preload images.
 */
jQuery.fn.rollover = function(preload) {
    this.filter(':not([src*="_h."])').each(function() {
        var a = this.src, b = this.src.replace(/\.(\w+(\?[^$]*)?)$/, '_h.$1');
        $(this).hover(function() { this.src = b; }, function() { this.src = a; });
        if (preload) {
            var i = new Image;
            i.src = b;
        }
    });
    return this;
};

$(function() {
   
    Boxy.DEFAULTS.closeText = '[X]';
   
    /***********************************************
    * Bookmark site script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
    * This notice MUST stay intact for legal use
    * Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
    * Modified for jQuery...
    ***********************************************/
    $('#bookmark-this-page').click(function() {
        var title = document.title;
        var url = window.location;
        if (window.sidebar && window.sidebar.addPanel) {
            window.sidebar.addPanel(title, url, '');
        } else if (window.opera && window.print) {
            var e = document.createElement('a');
            e.setAttribute('href', url);
            e.setAttribute('title', title);
            e.setAttribute('rel', 'sidebar');
            e.click();
        } else if (window.external) {
            window.external.AddFavorite(title, url);
        } else {
            alert('Sorry, this feature is not available on your browser');
        }
        return false;
    });
    
    $('#send-page-to-friend').boxy();
    $('a[rel=boxy]').boxy();

    $('input').each(function() { $(this).addClass(this.type); });
		
		if (!$.browser.msie || $.browser.version >= 7) {
			$('.rollover').rollover(true);
		} 
		
	
	$('#nav').droppy();
	
	$('.media-player').each(function() {
		var mediaUrl	= $(this).find('.media-url').attr('href'),
			width		= parseInt($(this).css('width'), 10),
			height		= parseInt($(this).css('height'), 10),
			background	= $(this).find('img').attr('src') || null,
			type		= $(this).is('.video-player') ? 'video' : 'sound',
			player		= createMediaPlayer(type, mediaUrl, width, height, background);
			
		player.write(this);
	});
});

(function() {
	
	var nextVideoIndex = 0;
	
	window.createMediaPlayer = function(type, url, width, height, bg) {
		var p = new SWFObject('/images/jw/player.swf', 'jw-player-' + (nextVideoIndex++), width, height, 9),
			fv = 'stretching=fill&file=' + url + '&type=' + type;
		if (bg) fv += '&image=' + bg;
		p.addParam('allowfullscreen', 'true');
		p.addParam('flashvars', fv);
		return p;
	}
	
})();
