<!--

$(document).ready(function() {

    if($('body#home').length>0 && navigator.userAgent.indexOf('MSIE') == -1) {
        
        $('<img>').attr('src', '/static/images/home_banner_hand.png')
                  .attr('id', 'hand')
                  .prependTo('#content');
        
        function fade_hand() {
            setTimeout(function() {
                $('body#home img#hand').fadeIn(1000);
            }, 1000);
        }

        if($('#hand').length>0) {
            $('body#home img#hand').ready(fade_hand);
        }

    }

    if($('body#keyfacts').length>0) {
        ul = $('<ul>').attr('id', 'kf_slideshow').appendTo('#subcontent_box');
        kf = 9;
        for(k=1; k<=kf; k++) {
            $('<li>')
                .attr('id', 'kf_li' + k)
                .html('<img src="/static/images/keyfacts_' + k + '.png" />')
                .appendTo(ul);
        }
        
        $('<div>').attr('id', 'action_links')
                  .html('<a id="play" href="#">Play</a>' +
                    '<a id="pause" href="#">Pause</a>')
                  .appendTo('#subcontent_box');
        
        $('#kf_li1').css({'display': 'list-item'});
        
        var current = 1,
            last = kf,
            interval = 7500;
        
        function start_slideshow() {
            if(current == last) {
                next = 1;
            } else {
                next = current + 1;
            }
                        
            $('#kf_li' + next).fadeIn('slow', function() {
                $('#kf_li' + current).fadeOut('slow');
                current = next;
                interval += interval;
            });
            
        }
        
        kf_interval = setInterval(start_slideshow, interval);
        
        $('#action_links #play').click(function() {
            interval = 7500;
            kf_interval = setInterval(start_slideshow, interval);
            return false;
        });
        
        $('#action_links #pause').click(function() {
            clearInterval(kf_interval);
            interval = 0;
            return false;
        });
    }

    if($('body.offices').length>0) {
        var active = $('#section0');
        $('#subcontent_nav a:first').addClass('active');
        $('#subcontent_nav a').click(function() {
            $('#subcontent_nav a').removeClass('active');
            $(this).addClass('active');
            
            var href = $(this).attr('href');
            $(active).fadeOut('slow',
                function() {
                    $(href).fadeIn('slow');
                });
            active = href;
            return false;
        });
    }

    $('#navigation').hover(
        function() {},
        function() {
            active_sections = $('body').attr('class').split(' ');
            sections_length = active_sections.length;
            selector_str = ''
            
            for(i=0; i<sections_length; i++)
            {
                selector_str += 'body.' + active_sections[i] + ' #nav_' + active_sections[i] + '_list,'
            }

            $('.sub_nav_1, .sub_nav_2')
                .not(selector_str)
                .css({'display': 'none'});
            
            $(selector_str).css({'display': 'block'});
            
            $('a', $(this)).removeClass('active');

            
        }
    );

    $('#navigation > li > a').hover(function() {
        $('.sub_nav_1, .sub_nav_2').css({'display': 'none'});
        $('a', $('#navigation')).removeClass('active');
        
        $('> .sub_nav_1', $(this).parent()).css({'display': 'block'});
        $(this).addClass('active');
    });
    
    $('#navigation > li > .sub_nav_1 > li > a').hover(function() {
        $('.sub_nav_2').css({'display': 'none'});
        $('.sub_nav_1 > li > a, .sub_nav_2 > li > a').removeClass('active');

        $('> .sub_nav_2', $(this).parent()).css({'display': 'block'});
        $(this).parent().closest('li > a').addClass('active');
        $(this).addClass('active');
    });
    
    $('.sub_nav_2 > li > a').hover(function() {
        $('.sub_nav_2 > li > a').removeClass('active');
        $(this).addClass('active');
    });

    /*---- SEARCH BAR ----*/
    
    var search_bar = $('#search_bar'),
        search_input = $('input', search_bar);
    
    $(search_input).focus(function() {
        $(this).val('');
        $(this).css({'color': '#333'});
    }).blur(function() {
        if($(this).val()=='') {
            $(this).css({'color': '#999'});
            $(this).val('Enter your search term...');
        }
    });

    /* ---- HOME NEWS TICKER ---- */
    
    if($('body').attr('id') == 'home') {
    	
    	$.getJSON('/xhr/rns/', function(data) {
	    	var result = $('div#ticker_area'),
       			interval = 7500,
            	item_count = data.length,
            	i = 0;
        	
        	function rotate_ticker() {
            	if(i == item_count) i = 0;

		        $(result).fadeOut('fast', function() {
        		  	$(this).html(
        		  		'<a href="http://online.hemscottir.com/ir/rqih/' + data[i].url + '" target="_blank">' +
        		  			'<span>' + data[i].headline + ' - ' + data[i].date + '</span>' +
        		  		'</a>'
        		  	)
            	}).fadeIn('fast');
            
            	i++;
        	}
        
        	rotate_ticker();
        	tickerInterval = setInterval(function() { rotate_ticker(); }, interval);
    	
    		/*result.live('click', function(e) {
    			e = e || event;
    		
    			var el = e.target || e.srcElement;
    			
    			if(el.tagName == 'SPAN') {
    				
    				if($('#rns_popup').length>0) {
    					$('#rns_popup').remove();
    				}
    				
    				html = '<div id="rns_popup">' +
    							'<iframe src="' + $(el).parent().attr('href') + '" />' +
    							'<a href="#" class="close">Close</a>' +
    						'</div>';
    						
    				$('body').append(html);
    				
    				var _top = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
    				
    				$('#rns_popup').css({
    					'left': (($(window).width()-$(this).width())/2)-30 + 'px',
    					'top': (($(window).height()-$(this).height)/2)+_top + 'px'
    				});
    			
    				$('#rns_popup > .close').click(function(e2) {
    					e2 = e2 || event;
    					
    					$(this).unbind('click');
    					$(this).parent().remove();
    					if(e2.target)
    					{
	    					e2.preventDefault();
	    				}
    					return false;
    				});
    			
    			}
    			
    			if(e.target)
    			{
	    			e.preventDefault();
	    		}
	    		
    			return false;
    		});*/
    	
    	});
    }
    
    /* ---- RENDEZVOUS IMAGE GALLERY ---- */
    if($('#rendezvous_gallery').length>0) {
    	var gallery = $('#rendezvous_gallery');
    	
    	$('#id_albums', gallery).change(function(e) {
    		var val = $(this).val();
    		$('.album').css({'display': 'none'});
    		$('#a' + val).css({'display': 'block'});
    		e.preventDefault();
    	});
    	
    	$('> .album > a', gallery).click(function() {
    		if(navigator.userAgent.indexOf('MSIE')==-1) {
				$('<div>')
				.attr('id', 'bgLayer')
				.appendTo('body');
			}
    		
    		var _top = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
    		
    		_src = $('> img', this).attr('src');
    		_ext = _src.split('.').pop();
    		
    		if(_src.indexOf('_100x100')!==-1) {
	    		_src = _src.substring(0, _src.indexOf('_100x100')) + '_420.' + _ext;
    		} else {
    			_src = _src.substring(0, _src.indexOf('s.jpg')) + '.' + _ext;
    		}
    		
    		obj = $(this);
    		
    		_caption = $('>img', obj).attr('alt');
    		
    		$('#bgLayer').css({'display': 'block'});
    		
			div = $('<div>')
						.attr('id', 'lightbox')
						.css({
							'left': ($('#container').width() - 32)/2 + 'px',
							'top': (($(window).height() - 32)/2)+_top + 'px'
						})
						.html('<img src="/static/images/loadspin.gif" />')
						.appendTo('#container');
    		
    		im = new Image();
    		im.src = _src;
    		
    		if($(div).length>0)
    		{
				im.onload = function() {
					$('> img', div).remove();
					
					$('<img>')
						.attr('src', _src)
						.appendTo(div);
					
					$('<p>')
						.html(_caption)
						.appendTo(div);
					
					$('<a>')
						.attr('href', '#')
						.html('Close')
						.css({
							'color': '#334',
							'background': '#fff',
							'padding': '2.5px 5px',
							'position': 'absolute',
							'top': '10px',
							'left': '10px'
						})
						.click(function() {
							$(this).parent().remove();
							$('#bgLayer').remove();
							return false;
						})
						.appendTo(div);
						
					$(div)
						.css({
							'left': ($('#container').width() - im.width)/2 + 'px',
							'top': (($(window).height()-im.height)/2)+_top + 'px'
						});
				}
			}
    		
    		$('#bgLayer').click(function() { div.remove(); $(this).remove(); });
    		
    		return false;
    	});
    	
    	$('.first', gallery).css({'display': 'block'});
    }
    
});

-->
