var Util = {
	resize: function()
	{
		var min_width = Element.getStyle(document.body, 'min-width');
		var set_width = ( min_width ) ? false : true;
	
		min_width = min_width || '1045';
		min_width = min_width.gsub('px', '');
		
		var width = document.viewport.getWidth();
		
		var right_pos = (( width < min_width ) ? (width - min_width) : 0) + 'px';
		//$('indices-container').setStyle({right: right_pos});
		
		if ( set_width )
		{
			var body_width = ( width < min_width ) ? '1045px' : '';
			Element.setStyle(document.body, {width: body_width});
		}
	},
	
	getScrollOffset: function()
	{
		var x = 0, y = 0;
		if ( typeof( window.pageYOffset ) == 'number' )
		{
			//Netscape
			y = window.pageYOffset;
			x = window.pageXOffset;
		}
		else if ( document.body && ( document.body.scrollLeft || document.body.scrollTop ) )
		{
			//DOM
			y = document.body.scrollTop;
			x = document.body.scrollLeft;
		}
		else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) )
		{
			//IE6 standards compliant mode
			y = document.documentElement.scrollTop;
			x = document.documentElement.scrollLeft;
		}
		return {left: x, top: y};
	},
	
	getMaxHeight: function(elements, inclusive)
	{
		// Check if height must include padding
		if ( inclusive == undefined )
		{
			inclusive = false;
		} 
		
		var max = 0
		var height;
		
		elements.each( function(element) {
			
			if ( !inclusive )
			{
				var padding = parseInt(element.getStyle('paddingTop').gsub('px', '')) + parseInt(element.getStyle('paddingBottom').gsub('px', ''));
			}
			else
			{
				var padding = 0;
			}
			
			var height = element.getHeight() - padding;
			if ( height > max )
			{
				max = height;
			}
		});
		
		return max;
	}
};

var Articles = {};

Articles.TopCarousel = Class.create(
{
    main_container: null,
    left_arrow:null,
    right_arrow:null,
    num_items:0,
    current:0,
    slider:null,
    shift_amount:3,
    block_width:334,
    sliding:false,
    current_pos:0,
    navigation:null,
    left_nav:null,
    right_nav:null,
    page_arr:null,
    
    initialize: function(main_container)
    {
        this.main_container = $('main_container');
        this.slider = $('topmm_main').down('div.topmm_slider');
        
        this.left_arrow = $('topmm_vert_scroll_left');
        this.right_arrow = $('topmm_vert_scroll_right');
        
        this.left_arrow.observe('click', this.scrollLeft.bind(this));
        this.right_arrow.observe('click', this.scrollRight.bind(this));
        
        this.slider.childElements().each(function(element)
        {
            if ( !element.hasClassName('clear') )
            {
                this.num_items++;
            }
        }.bind(this));
        
        this.slider.setStyle(
        {
            width:this.block_width*this.num_items + 'px'
        });
        
        this.navigation = $('topmm_block_scroll');
        
        var nav_row = this.navigation.down('tr');
        
        this.left_nav = new Element('td').update('<div class="sprite_main topmm_block_scroll_middle_disabled_left">&nbsp</div>');
        nav_row.insert(this.left_nav, {position:'bottom'});
        var pages = Math.ceil(this.num_items / this.shift_amount);
        
        this.page_arr = new Array(pages);
        
        for ( var i = 0; i < pages; i++ )
        {
            this.page_arr[i] = new Element('td');
            
            this.page_arr[i].observe('click', this.gotoPage.bind(this,i));
            
            if ( i == 0 )
            {
                this.page_arr[i].update('<div class="mm_scroll_dot sprite_main">&nbsp;</div>');
                
                this.page_arr[i].setStyle(
                {
                    cursor:'default',
                    textAlign:'center'
                });
            }
            else
            {
                this.page_arr[i].update('<div class="mm_grey_dot sprite_main">&nbsp;</div>');
                
                this.page_arr[i].setStyle(
                {
                    cursor:'pointer',
                    textAlign:'center'
                });
            }
            
            nav_row.insert(this.page_arr[i], {position:'bottom'});
        }
        
        this.right_nav = new Element('td', {style:'cursor:pointer;text-align:center'}).update('<div class="sprite_main topmm_block_scroll_middle_enabled_right">&nbsp</div>');
        nav_row.insert(this.right_nav, {position:'bottom'});
        
        this.left_nav.observe('click', this.scrollLeft.bind(this));
        this.right_nav.observe('click', this.scrollRight.bind(this));
    },
    
    loadedPage: function()
    {
        new Effect.Move(this.slider, {x:-170, duration: 5.0, mode: 'relative', afterFinish:this.doneSliding.bind(this)});
    },
    
    gotoPage: function(page_num)
    {
        if ( this.current == page_num || this.sliding )
        {
            return;
        }
        
        
        this.page_arr[page_num].down('div').removeClassName('mm_grey_dot');
        this.page_arr[page_num].down('div').addClassName('mm_scroll_dot');
        
        
        this.page_arr[page_num].setStyle(
        {
            cursor:'default'
        });
        
        
        this.page_arr[this.current].down('div').removeClassName('mm_scroll_dot');
        this.page_arr[this.current].down('div').addClassName('mm_grey_dot');
        
        this.page_arr[this.current].setStyle(
        {
            cursor:'pointer'
        });
        
        if ( page_num > this.current )
        {
            this.sliding = true;
            this.current_pos -= this.shift_amount * this.block_width * (page_num-this.current);
            
            new Effect.Move(this.slider, {x:-this.shift_amount*this.block_width*(page_num-this.current), duration: 0.5, mode: 'relative', afterFinish:this.doneSliding.bind(this)});
            
            this.current = page_num;
        }
        else
        {
            this.sliding = true;
            this.current_pos += this.shift_amount * this.block_width * (this.current - page_num);
            
            new Effect.Move(this.slider, {x:this.shift_amount*this.block_width*(this.current - page_num), duration: 0.5, mode: 'relative', afterFinish:this.doneSliding.bind(this)});
            
            this.current = page_num;
        }
        
        if ( this.current_pos < 0 )
        {
            this.left_arrow.down('img').src = 'http://us-cdn.creamermedia.co.za/template/polity/images/mm_arrow_left_vert.png';
            
            this.left_arrow.setStyle(
            {
                cursor:'pointer'
            });
            
            this.left_nav.down('div').removeClassName('topmm_block_scroll_middle_disabled_left');
            this.left_nav.down('div').addClassName('topmm_block_scroll_middle_enabled_left');
            
            this.left_nav.setStyle(
            {
                cursor:'pointer'
            });
        }
        else
        {
            this.left_arrow.down('img').src = 'http://us-cdn.creamermedia.co.za/template/polity/images/mm_arrow_left_vert_grey.png';
            
            this.left_arrow.setStyle(
            {
                cursor:'default'
            });
            
            this.left_nav.down('div').removeClassName('topmm_block_scroll_middle_enabled_left');
            this.left_nav.down('div').addClassName('topmm_block_scroll_middle_disabled_left');
            
            
            this.left_nav.setStyle(
            {
                cursor:'default'
            });
        }
        
        if ( (this.current_pos - (this.shift_amount * this.block_width)) > -(this.num_items * this.block_width) )
        {
            this.right_arrow.down('img').src = 'http://us-cdn.creamermedia.co.za/template/polity/images/mm_arrow_right_vert.png';
            
            this.right_arrow.setStyle(
            {
                cursor:'pointer'
            });
            
            this.right_nav.down('div').removeClassName('topmm_block_scroll_middle_disabled_right');
            this.right_nav.down('div').addClassName('topmm_block_scroll_middle_enabled_right');
            
            this.right_nav.setStyle(
            {
                cursor:'pointer'
            });
        }
        else
        {
            this.right_arrow.down('img').src = 'http://us-cdn.creamermedia.co.za/template/polity/images/mm_arrow_right_vert_grey.png';
            
            this.right_arrow.setStyle(
            {
                cursor:'default'
            });
            
            this.right_nav.down('div').removeClassName('topmm_block_scroll_middle_enabled_right');
            this.right_nav.down('div').addClassName('topmm_block_scroll_middle_disabled_right');
            
            this.right_nav.setStyle(
            {
                cursor:'default'
            });
        }
    },
    
    scrollLeft: function(event)
    {
        if ( this.current_pos == 0 || this.sliding )
        {
            return;
        }
        
        this.page_arr[this.current-1].down('div').removeClassName('mm_grey_dot');
        this.page_arr[this.current-1].down('div').addClassName('mm_scroll_dot');
        
        
        
        this.page_arr[this.current-1].setStyle(
        {
            cursor:'default'
        });
        
        this.page_arr[this.current].down('div').removeClassName('mm_scroll_dot');
        this.page_arr[this.current].down('div').addClassName('mm_grey_dot');
        
        
        this.page_arr[this.current].setStyle(
        {
            cursor:'pointer'
        });
        
        this.current -= 1;
        this.sliding = true;
        
        this.current_pos += this.shift_amount*this.block_width;
        
        new Effect.Move(this.slider, {x:this.shift_amount*this.block_width, duration: 0.5, mode: 'relative', afterFinish:this.doneSliding.bind(this)});
        
        if ( this.current_pos < 0 )
        {
            this.left_arrow.down('img').src = 'http://us-cdn.creamermedia.co.za/template/polity/images/mm_arrow_left_vert.png';
            
            this.left_arrow.setStyle(
            {
                cursor:'pointer'
            });
            
           this.left_nav.down('div').removeClassName('topmm_block_scroll_middle_disabled_left');
            this.left_nav.down('div').addClassName('topmm_block_scroll_middle_enabled_left');
            
            
            this.left_nav.setStyle(
            {
                cursor:'pointer'
            });
        }
        else
        {
            this.left_arrow.down('img').src = 'http://us-cdn.creamermedia.co.za/template/polity/images/mm_arrow_left_vert_grey.png';
            
            this.left_arrow.setStyle(
            {
                cursor:'default'
            });
            
            this.left_nav.down('div').removeClassName('topmm_block_scroll_middle_enabled_left');
            this.left_nav.down('div').addClassName('topmm_block_scroll_middle_disabled_left');
            
            this.left_nav.setStyle(
            {
                cursor:'default'
            });
        }
        
        if ( (this.current_pos - (this.shift_amount * this.block_width)) > -(this.num_items * this.block_width) )
        {
            this.right_arrow.down('img').src = 'http://us-cdn.creamermedia.co.za/template/polity/images/mm_arrow_right_vert.png';
            
            this.right_arrow.setStyle(
            {
                cursor:'pointer'
            });
            
            this.right_nav.down('div').removeClassName('topmm_block_scroll_middle_disabled_right');
            this.right_nav.down('div').addClassName('topmm_block_scroll_middle_enabled_right');
            
            this.right_nav.setStyle(
            {
                cursor:'pointer'
            });
        }
        else
        {
            this.right_arrow.down('img').src = 'http://us-cdn.creamermedia.co.za/template/polity/images/mm_arrow_right_vert_grey.png';
            
            this.right_arrow.setStyle(
            {
                cursor:'default'
            });

            this.right_nav.down('div').removeClassName('topmm_block_scroll_middle_enabled_right');
            this.right_nav.down('div').addClassName('topmm_block_scroll_middle_disabled_right');
            
            this.right_nav.setStyle(
            {
                cursor:'default'
            });
        }
    },
    
    scrollRight: function(event)
    {
        if ( (this.current_pos - (this.shift_amount * this.block_width)) <= -(this.num_items * this.block_width) || this.sliding )
        {
            return;
        }
        
        
        this.page_arr[this.current+1].down('div').removeClassName('mm_grey_dot');
        this.page_arr[this.current+1].down('div').addClassName('mm_scroll_dot');
        
        
        
        this.page_arr[this.current+1].setStyle(
        {
            cursor:'default'
        });
        
        this.page_arr[this.current].down('div').removeClassName('mm_scroll_dot');
        this.page_arr[this.current].down('div').addClassName('mm_grey_dot');
        
        
        this.page_arr[this.current].setStyle(
        {
            cursor:'pointer'
        });
        
        this.current += 1;
        this.sliding = true;
        
        this.current_pos -= this.shift_amount*this.block_width;
        
        new Effect.Move(this.slider, {x:-this.shift_amount*this.block_width, duration: 0.5, mode: 'relative', afterFinish:this.doneSliding.bind(this)});
        
        if ( this.current_pos < 0 )
        {
            this.left_arrow.down('img').src = 'http://us-cdn.creamermedia.co.za/template/polity/images/mm_arrow_left_vert.png';
            
            this.left_arrow.setStyle(
            {
                cursor:'pointer'
            });
            
            this.left_nav.down('div').removeClassName('topmm_block_scroll_middle_disabled_left');
            this.left_nav.down('div').addClassName('topmm_block_scroll_middle_enabled_left');
            
            
            this.left_nav.setStyle(
            {
                cursor:'pointer'
            });
        }
        else
        {
            this.left_arrow.down('img').src = 'http://us-cdn.creamermedia.co.za/template/polity/images/mm_arrow_left_vert_grey.png';
            
            this.left_arrow.setStyle(
            {
                cursor:'default'
            });
            
            this.left_nav.down('div').removeClassName('topmm_block_scroll_middle_enabled_left');
            this.left_nav.down('div').addClassName('topmm_block_scroll_middle_disabled_left');
            
            this.left_nav.setStyle(
            {
                cursor:'default'
            });
        }
        
        if ( (this.current_pos - (this.shift_amount * this.block_width)) > -(this.num_items * this.block_width) )
        {
            this.right_arrow.down('img').src = 'http://us-cdn.creamermedia.co.za/template/polity/images/mm_arrow_right_vert.png';
            
            this.right_arrow.setStyle(
            {
                cursor:'pointer'
            });
            
            this.right_nav.down('div').removeClassName('topmm_block_scroll_middle_disabled_right');
            this.right_nav.down('div').addClassName('topmm_block_scroll_middle_enabled_right');
            
            this.right_nav.setStyle(
            {
                cursor:'pointer'
            });
        }
        else
        {
            this.right_arrow.down('img').src = 'http://us-cdn.creamermedia.co.za/template/polity/images/mm_arrow_right_vert_grey.png';
            
            this.right_arrow.setStyle(
            {
                cursor:'default'
            });
            
            this.right_nav.down('div').removeClassName('topmm_block_scroll_middle_enabled_right');
            this.right_nav.down('div').addClassName('topmm_block_scroll_middle_disabled_right');
            
            this.right_nav.setStyle(
            {
                cursor:'default'
            });
        }
    },
    
    doneSliding: function(event)
    {
        this.sliding = false;
    }
});


var AllInstances = {
    instances: new Array(),
    expand: false,
    
    addInstance: function(instance)
    {
        AllInstances.instances.push(instance);
    },
    
    expandCollapseAll: function()
    {
        if ( AllInstances.expand == true )
        {
            AllInstances.expand = false;
            $('topmm_block_expand').update('Expand this page');
        }
        else
        {
            AllInstances.expand = true;
            $('topmm_block_expand').update('Collapse this page');
        }
        
        for (var i = 0; i < AllInstances.instances.length; i++)
        {
            if ( AllInstances.expand == true && AllInstances.instances[i].showAllIn == false )
            {
                AllInstances.instances[i].showAll();
            }
            else
            if ( AllInstances.expand == false && AllInstances.instances[i].showAllIn == true )
            {
                AllInstances.instances[i].showAll();
            }
        }
    }
}


Articles.Carousel = Class.create(
{
    page_num: 0,
    prev_page_num: -1,
    curr_prev_page_num: -1,
    slider: null,
    amount_to_move_last: 0,
    shift_amount: 0,
    upButton: null,
    downButton: null,
    page_0: null,
    page_1: null,
    page_2: null,
    allButton: null,
    allButton2: null,
    sliding: false,
    color: "page_blue",
    main_container: null,
    showAllIn: null,
    
    initialize: function(main_content_id, color)
    {
        this.main_container = $(main_content_id);
        this.slider = this.main_container.down('div.slider');
        this.shift_amount  = this.main_container.getHeight();
        this.color = color;
        var scroll_container = this.main_container.down('div.block_scrollbar');
        this.showAllIn = false;
        this.amount_to_move_last = 0;
        
        this.upButton = scroll_container.down('div.up');
        this.downButton = scroll_container.down('div.down');
        this.page_0 = scroll_container.down('div.vert_scroll_zero');
        this.page_1 = scroll_container.down('div.vert_scroll_one');
        this.page_2 = scroll_container.down('div.vert_scroll_two');
        this.allButton = this.main_container.down('div.all_button_out');
        this.allButton2 = this.main_container.down('div.home_blocks_bottom_bar_up_arrow');
        this.prev_page_num = -1;
        this.curr_prev_page_num = -1;
        
        this.upButton.observe('click', this.scrollUp.bind(this, 1));
        this.downButton.observe('click', this.scrollDown.bind(this, 1));
        this.page_0.observe('click', this.goToPage.bind(this, 0));
        this.page_1.observe('click', this.goToPage.bind(this, 1));
        this.page_2.observe('click', this.goToPage.bind(this, 2));
        this.allButton.observe('click', this.showAll.bind(this));
        this.allButton2.observe('click', this.showAll.bind(this));
        this.page_0.addClassName(this.color);
        this.page_1.addClassName(this.color);
        this.page_2.addClassName(this.color);
        
        AllInstances.addInstance(this);
    },
    
    scrollUp: function(page_amount)
    {
        if (this.page_num == 0 || this.sliding || this.showAllIn)
        {
            return;
        }
    
        
        this.sliding = true;
        new Effect.Move(this.slider, {y:this.shift_amount*page_amount+1, duration: 0.3, mode: 'relative', afterFinish:this.doneScrolling.bind(this)});
        
        this.prev_page_num = this.page_num;
        this.page_num-=page_amount;
        
        
        if (this.page_num != 2)
        {
            this.downButton.removeClassName('down_disabled');
            this.downButton.addClassName('down_enabled');
        }
        if (this.page_num == 0)
        {
            this.upButton.removeClassName('up_enabled');
            this.upButton.addClassName('up_disabled');
            this.page_0.removeClassName('unselected_page');
            this.page_1.removeClassName('selected_page');
            this.page_2.removeClassName('selected_page');
            this.page_0.addClassName('selected_page');
            this.page_0.addClassName(this.color);
            this.page_1.addClassName('unselected_page');
            this.page_2.addClassName('unselected_page');
        }
        else if (this.page_num == 1)
        {
            this.page_0.removeClassName('selected_page');
            this.page_1.removeClassName('unselected_page');
            this.page_2.removeClassName('selected_page');
            this.page_0.addClassName('unselected_page');
            this.page_1.addClassName('selected_page');
            this.page_1.addClassName(this.color);
            this.page_2.addClassName('unselected_page');
        }
        else if (this.page_num == 2)
        {
            this.page_0.removeClassName('selected_page');
            this.page_1.removeClassName('selected_page');
            this.page_2.removeClassName('unselected_page');
            this.page_0.addClassName('unselected_page');
            this.page_1.addClassName('unselected_page');
            this.page_1.addClassName(this.color);
            this.page_2.addClassName('selected_page');
        }
        
    },
    
    scrollDown: function(page_amount)
    {
        if (this.page_num == 2 || this.sliding|| this.showAllIn)
        {
            return;
        }
    
        
        this.sliding = true;
        
        
        new Effect.Move(this.slider, {y:-this.shift_amount*page_amount-1, duration: 0.3, mode: 'relative', afterFinish:this.doneScrolling.bind(this)});
        
        this.prev_page_num = this.page_num;
        this.page_num+=page_amount;
        
        if (this.page_num != 0)
        {
            this.upButton.removeClassName('up_disabled');
            this.upButton.addClassName('up_enabled');
        }
        if (this.page_num == 0)
        {
            this.page_0.removeClassName('unselected_page');
            this.page_1.removeClassName('selected_page');
            this.page_2.removeClassName('selected_page');
            this.page_0.addClassName('selected_page');
            this.page_1.addClassName('unselected_page');
            this.page_0.addClassName(this.color);
            this.page_2.addClassName('unselected_page');
        }
        else if (this.page_num == 1)
        {
            this.page_0.removeClassName('selected_page');
            this.page_1.removeClassName('unselected_page');
            this.page_2.removeClassName('selected_page');
            this.page_0.addClassName('unselected_page');
            this.page_1.addClassName('selected_page');
            this.page_1.addClassName(this.color);
            this.page_2.addClassName('unselected_page');
        }
        else if (this.page_num == 2)
        {
            this.downButton.removeClassName('down_enabled');
            this.downButton.addClassName('down_disabled');
            this.page_0.removeClassName('selected_page');
            this.page_1.removeClassName('selected_page');
            this.page_2.removeClassName('unselected_page');
            this.page_0.addClassName('unselected_page');
            this.page_1.addClassName('unselected_page');
            this.page_2.addClassName(this.color);
            this.page_2.addClassName('selected_page');
        }
        
    },
    
    goToPage: function(page_nr)
    {
        if (page_nr == this.page_num)
        {
            return;
        }
        if (page_nr > this.page_num)
        {
            var amount = page_nr-this.page_num;
            this.scrollDown(amount);
        }
        else
        {
            var amount = this.page_num-page_nr;
            this.scrollUp(amount);
        }
    },
    
    showAll: function()
    {
        if (this.sliding)
        {
            return;
        }
        
        
        if (this.page_num > 0)
        {
            this.curr_prev_page_num = this.prev_page_num;
    
            this.goToPage(0);
        }
        
        
        this.sliding = true;
        
        
        
        if (this.main_container.getHeight() > this.shift_amount)
        {
                 
            new Effect.Morph(this.main_container,
            {
                style: 'height:' + (this.shift_amount) + 'px',
                duration:0.3,
                afterFinish: this.doneScrolling()
            });
            
            this.downButton.removeClassName('down_disabled');
            this.downButton.addClassName('down_enabled');
            this.page_0.removeClassName('unselected_page');
            this.page_1.removeClassName('selected_page');
            this.page_2.removeClassName('selected_page');
            this.page_0.addClassName('selected_page');
            this.page_0.addClassName(this.color);
            this.page_1.addClassName('unselected_page');
            this.page_2.addClassName('unselected_page');
            this.page_0.removeClassName('unselected');
            this.page_1.removeClassName('unselected');
            this.page_2.removeClassName('unselected');
            this.allButton.removeClassName('all_button_in');
            this.allButton.addClassName('all_button_out');
            //this.allButton.src = "images/all_button.png";
            this.showAllIn = false;
        }
        else
        {
            
            
            new Effect.Morph(this.main_container,
            {
                style: 'height:' + (this.shift_amount*3+37) + 'px',
                duration:0.3,
                afterFinish: this.doneScrolling()
            });
            
            
            if (this.curr_prev_page_num == 1)
            {
                this.amount_to_move_last = this.shift_amount - this.shift_amount*3 - 1;
                //alert(this.shift_amount + "     " + this.shift_amount*3);
                this.slider.setStyle(
                {
                    top : this.amount_to_move_last + 'px'
                });
            
            }
            
            this.downButton.removeClassName('down_enabled');
            this.upButton.removeClassName('up_enabled');
            this.downButton.addClassName('down_disabled');
            this.upButton.addClassName('up_disabled');
            this.page_0.removeClassName('selected_page');
            this.page_1.removeClassName('selected_page');
            this.page_2.removeClassName('selected_page');
            this.page_0.addClassName('unselected_page');
            this.page_1.addClassName('unselected_page');
            this.page_2.addClassName('unselected_page');
            this.page_0.addClassName('unselected');
            this.page_1.addClassName('unselected');
            this.page_2.addClassName('unselected');
            this.allButton.removeClassName('all_button_out');
            this.allButton.addClassName('all_button_in');
            //this.allButton.src = "images/all_in_button.png";
            this.showAllIn = true;
        }
        
    },
    
    doneScrolling: function()
    {
        this.sliding = false;
    }
});



Articles.Accordion = Class.create(
{    
    right_block_container: null,
    right_block_slider: null,
    topBarClick: null,
    isOpen: null,
    busySliding: null,
    rightBlocksBar: null,

    initialize: function(main_content_id)
    {
        this.right_block_container = $(main_content_id);
        this.rightBlocksBar = this.right_block_container.down('div.view_right_blocks_bar')
        this.right_block_slider = this.right_block_container.down('div.right_block_slider');
        this.topBarClick = this.right_block_container.down('div.view_right_blocks_bar');
        this.isOpen = true;
        this.busySliding = false;
        this.topBarClick.observe('click', this.slideBlock.bind(this));        
    },
    
    slideBlock: function()
    {
        if (this.busySliding)
        {
            return;
        }
        if (this.isOpen)
        {
            this.busySliding = true;
            new Effect.SlideUp(this.right_block_slider,{ duration:0.3, afterFinish: this.doneSliding.bind(this) });
            this.rightBlocksBar.down('img').src = 'http://us-cdn.creamermedia.co.za/template/polity/images/view_rightblock_arrow_right.png';
            this.isOpen = false;
            
        }
        else
        {
            this.busySliding = true;
            new Effect.SlideDown(this.right_block_slider, { duration:0.3, afterFinish:this.doneSliding.bind(this)});
            this.rightBlocksBar.down('img').src = 'http://us-cdn.creamermedia.co.za/template/polity/images/view_rightblock_arrow_down.png';
            this.isOpen = true;
        }
    },
    
    doneSliding: function()
    {
        this.busySliding = false;
    }
});









Articles.QuotesAccordion = Class.create(
{    
    right_block_container: null,
    right_block_slider: null,
    quote_slider: null,
    topBarClick: null,
    isOpen: null,
    busySliding: null,
    rightBlocksBar: null,
    trrow: null,
    ttable: null,
    counter: 0,

    initialize: function(main_content_id)
    {
        
        this.right_block_container = $(main_content_id);
        this.rightBlocksBar = this.right_block_container.down('div#previous_poll_block')
        this.right_block_slider = this.right_block_container.down('div#previous_poll_block_inner');
        this.topBarClick = this.right_block_container.down('div#previous_poll_block');
        
        this.busySliding = false;
        this.topBarClick.observe('click', this.slideBlock.bind(this));
        this.tdiv = $('quote_block_scroll_middle');
        new Effect.SlideUp(this.right_block_slider,{ duration:0.3, afterFinish: this.doneSliding.bind(this) });
        this.isOpen = false;
        
        if (this.tdiv != null)
        {
            this.ttable = this.tdiv.down('table#quote_arrow_table');
            this.trrow = this.ttable.down('tr');   
        }
    },
    
     
    slideBlock: function()
    {
        if (this.busySliding)
        {
            return;
        }
        if (this.isOpen)
        {
            this.busySliding = true;
            new Effect.SlideUp(this.right_block_slider,{ duration:0.3, afterFinish: this.doneSliding.bind(this) });
            this.isOpen = false;
            
        }
        else
        {
            if (this.tdiv != null)
            {
                var the_children = this.trrow.childElements();
                    the_children.each(function(td_item)
                    {
                        td_item.down('div').addClassName('mm_grey_dot');
                        td_item.down('div').removeClassName('dot_color quote_dot_color');
                        
                        if (this.counter == 1)
                        {
                            td_item.down('div').addClassName('dot_color quote_dot_color');
                            td_item.down('div').removeClassName('mm_grey_dot');
                        }
                        this.counter++;
                    }.bind(this));
            }                
               
            this.busySliding = true;
            new Effect.SlideDown(this.right_block_slider, { duration:0.3, afterFinish:this.doneSliding.bind(this)});
            this.isOpen = true;
        }
    },
    
    doneSliding: function()
    {
        this.busySliding = false;
    }
});









Articles.AccordionLB = Class.create(
{    
    right_block_container: null,
    right_block_slider: null,
    topBarClick: null,
    isOpen: null,
    busySliding: null,
    rightBlocksBar: null,

    initialize: function(main_content_id, isOpenVar)
    {
        this.right_block_container = $(main_content_id);
        this.rightBlocksBar = this.right_block_container.down('div.view_right_blocks_bar')
        this.rightBlocksBar2 = this.right_block_container.down('span.view_right_blocks_bar2')
        this.lbSpacer = this.right_block_container.down('div.lb_spacer')
        this.right_block_slider = this.right_block_container.down('div.right_block_slider_lb');
        this.topBarClick = this.right_block_container.down('div.view_right_blocks_bar');
        this.topBarClick2 = this.right_block_container.down('span.view_right_blocks_bar2');
        this.isOpen = isOpenVar;
        this.busySliding = false;
        this.topBarClick.observe('click', this.slideBlock.bind(this));        
        this.topBarClick2.observe('click', this.slideBlock.bind(this));
        if (!this.isOpen)
            new Effect.SlideUp(this.right_block_slider,{ duration:0.3, afterFinish: this.doneSliding.bind(this) });        
    },
    
    slideBlock: function()
    {
        if (this.busySliding)
        {
            return;
        }
        if (this.isOpen)
        {
            this.busySliding = true;
            new Effect.SlideUp(this.right_block_slider,{ duration:0.3, afterFinish: this.doneSliding.bind(this) });
            this.rightBlocksBar.down('img').src = 'http://us-cdn.creamermedia.co.za/template/polity/images/showfilters.png';
            this.rightBlocksBar2.update('Show filters');
           
            
            /*this.lbSpacer.setStyle(
            {
            display: 'block'
            });*/
            
            this.isOpen = false;
            
        }
        else
        {
            this.busySliding = true;
            new Effect.SlideDown(this.right_block_slider, { duration:0.3, afterFinish:this.doneSliding.bind(this)});
            this.rightBlocksBar.down('img').src = 'http://us-cdn.creamermedia.co.za/template/polity/images/hidefilters.png';
            this.rightBlocksBar2.update('Hide filters');
            /* this.lbSpacer.setStyle(
            {
            display: 'none'
            });*/
            this.isOpen = true;
        }
    },
    
    doneSliding: function()
    {
        this.busySliding = false;
    }
});














Accordion_Abstracts = Class.create(
{    
    right_block_container: null,
    right_block_slider: null,
    headlineHover: null,
    isHovering: null,
    busySliding: null,
    rightBlocksBar: null,

    initialize: function(main_content_id)
    {
        this.block_container = $(main_content_id);
        
        this.block_slider = this.block_container.down('div.block_slider');
        //this.headlineHover = this.block_container.down('div.landing_page_list_articles_item_headline');
        this.isHovering = false;
        this.busySliding = false;
        new Effect.SlideUp(this.block_slider,{ duration:0.3, afterFinish: this.doneSliding.bind(this) });
        this.block_container.observe('mouseover', this.slideBlockOpen.bind(this));        
        this.block_container.observe('mouseout', this.slideBlockClose.bind(this));        
    },
    
    slideBlockOpen: function(event)
    {

        
        if (this.busySliding || this.isHovering)
        {
            return;
        }
        
        this.isHovering = true;
        this.busySliding = true;
        new Effect.SlideDown(this.block_slider, { duration:0.3, afterFinish:this.doneSliding.bind(this)});        
    },
    
    slideBlockClose: function(event)
    {
   
        
        if (this.busySliding || !this.isHovering)
        {
            return;
        }
        
        this.isHovering = false;
        this.busySliding = true;
        new Effect.SlideUp(this.block_slider,{ duration:0.3, afterFinish: this.doneSliding.bind(this) });
    },
    
    doneSliding: function()
    {
        this.busySliding = false;
    }
});

function changeArrow(element)
{

    element.up('ul').childElements().each(function(list_item)
    {
        list_item.down('img').src = 'http://us-cdn.creamermedia.co.za/template/polity/images/view_rightblock_arrow_right.png';
        
    });
    element.down('img').src='http://us-cdn.creamermedia.co.za/template/polity/images/view_rightblock_arrow_down.png'
    
};



function changeFontSize(size)
{
    var currentSize = parseInt($('view_article_middle_column').getStyle('fontSize'));
    
    var upperLimit = 20;
    var lowerLimit = 10;
    
    if ((size == "larger") && (currentSize < upperLimit))
    {
        $('view_article_middle_column').style.fontSize = currentSize + 1 + "px";
    }
    else if ((size == "smaller")  && (currentSize > lowerLimit))
    {
        $('view_article_middle_column').style.fontSize = currentSize - 1 + "px";
    }
    else if (size == "reset")
    {
        $('view_article_middle_column').style.fontSize = "12px";
    }
    
};

function setCorrectSizes()
{
         $('topmm_vert_scroll_left').setStyle(
         {
            height: $('topmm_main').getHeight() + 'px'
         });
         
         $('topmm_vert_scroll_right').setStyle(
         {
            height: $('topmm_main').getHeight() + 'px'
         });
         
         $('topmm_vert_scroll_left').down('img').setStyle(
         {
            marginTop: ($('topmm_main').getHeight()/2-2) + 'px'
         });
         $('topmm_vert_scroll_right').down('img').setStyle(
         {
            marginTop: ($('topmm_main').getHeight()/2-2) + 'px'
         });
          
};

Articles.ExpandCollapseAbstract = Class.create(
{
    main_container: null,
    abstract_open: false,
    abstract_slider: null,
    opening: false,
    over_container: false,
    counter: 0,
    timeout: null,
    
    initialize: function(container_id)
    {
        this.main_container = $(container_id);
        this.abstract_slider = this.main_container.down('div.landing_page_item_abstract_container');
        
        this.main_container.observe('mousemove', this.openCloseAbstractTimeout.bind(this));
        this.main_container.observe('mouseout', this.outOfContainerTimeout.bind(this));
    },
    
    outOfContainerTimeout: function()
    {
        if ( this.timeout != null )
        {
            clearTimeout(this.timeout);
            this.timeout = null;
        }
        
        this.over_container = false;
        
        if ( !this.abstract_open || this.opening )
        {
            return;
        }
        
        this.timeout = setTimeout(this.outOfContainer.bind(this), 100);
    },
    
    outOfContainer: function(event)
    {
        this.opening = true;
        this.abstract_open = false;
        new Effect.SlideUp(this.abstract_slider, { duration:0.2, afterFinish: this.doneOpeningClosing.bind(this) });
    },
    
    openCloseAbstractTimeout: function(event)
    {
        if ( this.timeout != null )
        {
            clearTimeout(this.timeout);
            this.timeout = null;
        }
        
        this.over_container = true;
        
        if ( this.abstract_open || this.opening )
        {
            return;
        }
        
        this.timeout = setTimeout(this.openCloseAbstract.bind(this), 100);
    },
    
    openCloseAbstract: function(event)
    {
        if ( this.timeout != null )
        {
            clearTimeout(this.timeout);
            this.timeout = null;
        }
        
        if ( !this.over_container )
        {
            this.over_container = true;
        }
        
        if ( this.opening )
        {
            return;
        }
        
        if ( !this.abstract_open && this.over_container )
        {
            this.opening = true;
            this.abstract_open = true;
            new Effect.SlideDown(this.abstract_slider, { duration:0.2, afterFinish: this.doneOpeningClosing.bind(this) });
        }
    },
    
    doneOpeningClosing: function(event)
    {
        this.opening = false;
        
        if ( !this.over_container )
        {
            this.outOfContainerTimeout();
        }
    }
});


Articles.ExpandCollapseAbstractLast = Class.create(
{
    main_container: null,
    main_slider: null,
    abstract_open: false,
    abstract_slider: null,
    opening: false,
    over_container: false,
    counter: 0,
    timeout: null,
    
    initialize: function(container_id, lastDiv)
    {
        this.main_container = $(container_id);
        this.abstract_slider = this.main_container.down('div.landing_page_item_abstract_container');
        this.main_slider = $(lastDiv);
        this.main_container.observe('mousemove', this.openCloseAbstractTimeout.bind(this));
        this.main_container.observe('mouseout', this.outOfContainerTimeout.bind(this));
    },
    
    outOfContainerTimeout: function()
    {
        if ( this.timeout != null )
        {
            clearTimeout(this.timeout);
            this.timeout = null;
        }
        
        this.over_container = false;
        
        if ( !this.abstract_open || this.opening )
        {
            return;
        }
        
        this.timeout = setTimeout(this.outOfContainer.bind(this), 100);
    },
    
    outOfContainer: function(event)
    {
        this.opening = true;
        this.abstract_open = false;
        new Effect.SlideUp(this.abstract_slider, { duration:0.2, afterFinish: this.doneOpeningClosing.bind(this) });
    },
    
    openCloseAbstractTimeout: function(event)
    {
        if ( this.timeout != null )
        {
            clearTimeout(this.timeout);
            this.timeout = null;
        }
        
        this.over_container = true;
        
        if ( this.abstract_open || this.opening )
        {
            return;
        }
        
        this.timeout = setTimeout(this.openCloseAbstract.bind(this), 100);
    },
    
    openCloseAbstract: function(event)
    {
        if ( this.timeout != null )
        {
            clearTimeout(this.timeout);
            this.timeout = null;
        }
        
        if ( !this.over_container )
        {
            this.over_container = true;
        }
        
        if ( this.opening )
        {
            return;
        }
        
        if ( !this.abstract_open && this.over_container )
        {
            this.opening = true;
            this.abstract_open = true;
            new Effect.SlideDown(this.abstract_slider, { duration:0.2, afterFinish: this.doneOpeningClosing.bind(this) });
        }
    },
    
    doneOpeningClosing: function(event)
    {
        this.opening = false;
         this.main_slider.scrollTop = 10000;
        if ( !this.over_container )
        {
            this.outOfContainerTimeout();
        }
    }
});























































Articles.QuoteCarousel = Class.create(
{
    main_container: null,
    left_arrow:null,
    right_arrow:null,
    num_items:0,
    current:0,
    quote_slider:null,
    shift_amount:1,
    block_width:320,
    sliding:false,
    current_pos:0,
    navigation:null,
    left_nav:null,
    right_nav:null,
    page_arr:null,
    imgLinkArr:null,
    imgLink1:null,
    imgLink2:null,
    imgLink3:null,
    imgLinkCurrent:null,
    pagenum:0,
    
    initialize: function(main_container)
    {
        this.main_container = $('landing_page_quote');
        this.quote_slider = $('landing_page_block_slider_quote_container');
        
        this.quote_slider.childElements().each(function(element)
        {
            if ( element.hasClassName('landing_pullout_text'))
            {
                this.num_items++;
            }
        }.bind(this));

        this.quote_slider.setStyle(
        {
            width:this.block_width*this.num_items + 'px'
        });
    
        this.navigation = $('quote_block_scroll');
        
        var nav_row = this.navigation.down('tr');
    
        this.left_nav = new Element('td').update('<div class="sprite_main quote_block_scroll_middle_disabled_left">&nbsp</div>');
        
        this.left_nav.setStyle(
            {
                width:'35px'
            });
        
        
        nav_row.insert(this.left_nav, {position:'bottom'});
    
        var pages = Math.ceil(this.num_items / this.shift_amount);
        
        this.page_arr = new Array(pages);
        
        for ( var i = 0; i < pages; i++ )
        {
            this.page_arr[i] = new Element('td');
            
            this.page_arr[i].observe('click', this.gotoPage.bind(this,i));
            
            if ( i == 0 )
            {
                this.page_arr[i].update('<div class="dot_color quote_dot_color sprite_main">&nbsp;</div>');
                
                this.page_arr[i].setStyle(
                {
                    cursor:'default',
                    textAlign:'center'
                });
            }
            else
            {
                this.page_arr[i].update('<div class="mm_grey_dot sprite_main">&nbsp;</div>');
                
                this.page_arr[i].setStyle(
                {
                    cursor:'pointer',
                    textAlign:'center'
                });
            }
            
            nav_row.insert(this.page_arr[i], {position:'bottom'});
            //imgLinkArr[i] = $('landing_block_' + (i+1)).readAttribute('src');
            
        }
        //alert(imgLinkArr[0] + " : " + imgLinkArr[1] + " : " + imgLinkArr[2]);
        this.right_nav = new Element('td', {style:'cursor:pointer;text-align:center'}).update('<div class="sprite_main quote_block_scroll_middle_enabled_right">&nbsp</div>');
        nav_row.insert(this.right_nav, {position:'bottom'});
        
        this.left_nav.observe('click', this.scrollLeft.bind(this));
        this.right_nav.observe('click', this.scrollRight.bind(this));
        
        this.imgLink1 = $('landing_block_1').readAttribute('src');
        this.imgLinkCurrent = $('landing_block_1').readAttribute('src');
        this.imgLink2 = $('landing_block_2').readAttribute('src');
        this.imgLink3 = $('landing_block_3').readAttribute('src');
        
        $('go_to_article_button').href = $('landing_block_1').readAttribute('src');
    },
        
    
    gotoPage: function(page_num)
    {
        if ( this.current == page_num || this.sliding )
        {
            return;
        }
        
        this.pagenum = page_num+1;
        if (this.pagenum == 1)
        {
            this.imgLinkCurrent = this.imgLink1;
        }
        else if (this.pagenum == 2)
        {
            this.imgLinkCurrent = this.imgLink2;
        }
        else if (this.pagenum == 3)
        {
            this.imgLinkCurrent = this.imgLink3;
        }
        $('go_to_article_button').writeAttribute(
        {
            href:this.imgLinkCurrent
        });
        
        
        this.page_arr[page_num].down('div').removeClassName('mm_grey_dot');
        this.page_arr[page_num].down('div').addClassName('dot_color quote_dot_color');
  
        
        this.page_arr[page_num].setStyle(
        {
            cursor:'default'
        });
        
        
        this.page_arr[this.current].down('div').removeClassName('dot_color quote_dot_color');
        this.page_arr[this.current].down('div').addClassName('mm_grey_dot');
        
        this.page_arr[this.current].setStyle(
        {
            cursor:'pointer'
        });
        
        if ( page_num > this.current )
        {
            this.sliding = true;
            this.current_pos -= this.shift_amount * this.block_width * (page_num-this.current);
            
            new Effect.Move(this.quote_slider, {x:-this.shift_amount*this.block_width*(page_num-this.current), duration: 0.5, mode: 'relative', afterFinish:this.doneSliding.bind(this)});
            
            this.current = page_num;
        }
        else
        {
            this.sliding = true;
            this.current_pos += this.shift_amount * this.block_width * (this.current - page_num);
            
            new Effect.Move(this.quote_slider, {x:this.shift_amount*this.block_width*(this.current - page_num), duration: 0.5, mode: 'relative', afterFinish:this.doneSliding.bind(this)});
            
            this.current = page_num;
        }
        
        if ( this.current_pos < 0 )
        {
            
            
            this.left_nav.down('div').removeClassName('quote_block_scroll_middle_disabled_left');
            this.left_nav.down('div').addClassName('quote_block_scroll_middle_enabled_left');
            
            this.left_nav.setStyle(
            {
                cursor:'pointer',
                width:'35px'
            });
        }
        else
        {
            
            
            this.left_nav.down('div').removeClassName('quote_block_scroll_middle_enabled_left');
            this.left_nav.down('div').addClassName('quote_block_scroll_middle_disabled_left');
            
            
            this.left_nav.setStyle(
            {
                cursor:'default',
                width:'35px'
            });
        }
        
        if ( (this.current_pos - (this.shift_amount * this.block_width)) > -(this.num_items * this.block_width) )
        {
            
            
            this.right_nav.down('div').removeClassName('quote_block_scroll_middle_disabled_right');
            this.right_nav.down('div').addClassName('quote_block_scroll_middle_enabled_right');
            
            this.right_nav.setStyle(
            {
                cursor:'pointer'
            });
        }
        else
        {
            
            
            this.right_nav.down('div').removeClassName('quote_block_scroll_middle_enabled_right');
            this.right_nav.down('div').addClassName('quote_block_scroll_middle_disabled_right');
            
            this.right_nav.setStyle(
            {
                cursor:'default'
            });
        }
    },
    
    scrollLeft: function(event)
    {
        if ( this.current_pos == 0 || this.sliding )
        {
            return;
        }
        
        
        this.pagenum = this.current;
        if (this.pagenum == 1)
        {
            this.imgLinkCurrent = this.imgLink1;
        }
        else if (this.pagenum == 2)
        {
            this.imgLinkCurrent = this.imgLink2;
        }
        else if (this.pagenum == 3)
        {
            this.imgLinkCurrent = this.imgLink3;
        }
        $('go_to_article_button').writeAttribute(
        {
            href:this.imgLinkCurrent
        });
        
        
        
        this.page_arr[this.current-1].down('div').removeClassName('mm_grey_dot');
        this.page_arr[this.current-1].down('div').addClassName('dot_color quote_dot_color');
        
        
        
        this.page_arr[this.current-1].setStyle(
        {
            cursor:'default'
        });
        
        this.page_arr[this.current].down('div').removeClassName('dot_color quote_dot_color');
        this.page_arr[this.current].down('div').addClassName('mm_grey_dot');
        
        
        this.page_arr[this.current].setStyle(
        {
            cursor:'pointer'
        });
        
        this.current -= 1;
        this.sliding = true;
        
        this.current_pos += this.shift_amount*this.block_width;
        
        new Effect.Move(this.quote_slider, {x:this.shift_amount*this.block_width, duration: 0.5, mode: 'relative', afterFinish:this.doneSliding.bind(this)});
        
        if ( this.current_pos < 0 )
        {
            
            
           this.left_nav.down('div').removeClassName('quote_block_scroll_middle_disabled_left');
            this.left_nav.down('div').addClassName('quote_block_scroll_middle_enabled_left');
            
            
            this.left_nav.setStyle(
            {
                cursor:'pointer',
                width:'35px'
            });
        }
        else
        {
            
            
            this.left_nav.down('div').removeClassName('quote_block_scroll_middle_enabled_left');
            this.left_nav.down('div').addClassName('quote_block_scroll_middle_disabled_left');
            
            this.left_nav.setStyle(
            {
                cursor:'default',
                width:'35px'
            });
        }
        
        if ( (this.current_pos - (this.shift_amount * this.block_width)) > -(this.num_items * this.block_width) )
        {
            
            
            this.right_nav.down('div').removeClassName('quote_block_scroll_middle_disabled_right');
            this.right_nav.down('div').addClassName('quote_block_scroll_middle_enabled_right');
            
            this.right_nav.setStyle(
            {
                cursor:'pointer'
            });
        }
        else
        {
            

            this.right_nav.down('div').removeClassName('quote_block_scroll_middle_enabled_right');
            this.right_nav.down('div').addClassName('quote_block_scroll_middle_disabled_right');
            
            this.right_nav.setStyle(
            {
                cursor:'default'
            });
        }
    },
    
    scrollRight: function(event)
    {
        if ( (this.current_pos - (this.shift_amount * this.block_width)) <= -(this.num_items * this.block_width) || this.sliding )
        {
            return;
        }
        
        this.pagenum = this.current+2;
        if (this.pagenum == 1)
        {
            this.imgLinkCurrent = this.imgLink1;
        }
        else if (this.pagenum == 2)
        {
            this.imgLinkCurrent = this.imgLink2;
        }
        else if (this.pagenum == 3)
        {
            this.imgLinkCurrent = this.imgLink3;
        }
        $('go_to_article_button').writeAttribute(
        {
            href:this.imgLinkCurrent
        });
        
        this.page_arr[this.current+1].down('div').removeClassName('mm_grey_dot');
        this.page_arr[this.current+1].down('div').addClassName('dot_color quote_dot_color');
        
        
        
        this.page_arr[this.current+1].setStyle(
        {
            cursor:'default'
        });
        
        this.page_arr[this.current].down('div').removeClassName('dot_color quote_dot_color');
        this.page_arr[this.current].down('div').addClassName('mm_grey_dot');
        
        
        this.page_arr[this.current].setStyle(
        {
            cursor:'pointer'
        });
        
        this.current += 1;
        this.sliding = true;
        
        this.current_pos -= this.shift_amount*this.block_width;
        
        new Effect.Move(this.quote_slider, {x:-this.shift_amount*this.block_width, duration: 0.5, mode: 'relative', afterFinish:this.doneSliding.bind(this)});
        
        if ( this.current_pos < 0 )
        {
            
            
            this.left_nav.down('div').removeClassName('quote_block_scroll_middle_disabled_left');
            this.left_nav.down('div').addClassName('quote_block_scroll_middle_enabled_left');
            
            
            this.left_nav.setStyle(
            {
                cursor:'pointer',
                width:'35px'
            });
        }
        else
        {
            
            
            this.left_nav.down('div').removeClassName('topmm_block_scroll_middle_enabled_left');
            this.left_nav.down('div').addClassName('quote_block_scroll_middle_disabled_left');
            
            this.left_nav.setStyle(
            {
                cursor:'default',
                width:'35px'
            });
        }
        
        if ( (this.current_pos - (this.shift_amount * this.block_width)) > -(this.num_items * this.block_width) )
        {
            
            
            this.right_nav.down('div').removeClassName('quote_block_scroll_middle_disabled_right');
            this.right_nav.down('div').addClassName('quote_block_scroll_middle_enabled_right');
            
            this.right_nav.setStyle(
            {
                cursor:'pointer'
            });
        }
        else
        {
            
            
            this.right_nav.down('div').removeClassName('quote_block_scroll_middle_enabled_right');
            this.right_nav.down('div').addClassName('quote_block_scroll_middle_disabled_right');
            
            this.right_nav.setStyle(
            {
                cursor:'default'
            });
        }
    },
    
    doneSliding: function(event)
    {
        this.sliding = false;
    }
});

















Articles.PhotoCarousel = Class.create(
{
    main_container: null,
    left_arrow:null,
    right_arrow:null,
    num_items:0,
    current:0,
    photo_slider:null,
    shift_amount:1,
    block_width:320,
    sliding:false,
    current_pos:0,
    navigation:null,
    left_nav:null,
    right_nav:null,
    page_arr:null,
    imgLinkArr:null,
    imgLink1:null,
    imgLink2:null,
    imgLink3:null,
    imgLinkCurrent:null,
    pagenum:0,
    
    initialize: function(main_container)
    {
        this.main_container = $('landing_page_photo');
        this.photo_slider = $('landing_page_block_slider_photo_container');
        
        this.photo_slider.childElements().each(function(element)
        {
            if ( element.hasClassName('landing_pullout_text'))
            {
                this.num_items++;
            }
        }.bind(this));

        this.photo_slider.setStyle(
        {
            width:this.block_width*this.num_items + 'px'
        });
    
        this.navigation = $('photo_block_scroll');
        
        var nav_row = this.navigation.down('tr');
    
        this.left_nav = new Element('td').update('<div class="sprite_main quote_block_scroll_middle_disabled_left">&nbsp</div>');
        
        this.left_nav.setStyle(
            {
                width:'35px'
            });
        
        
        nav_row.insert(this.left_nav, {position:'bottom'});
    
        var pages = Math.ceil(this.num_items / this.shift_amount);
        
        this.page_arr = new Array(pages);
        
        for ( var i = 0; i < pages; i++ )
        {
            this.page_arr[i] = new Element('td');
            
            this.page_arr[i].observe('click', this.gotoPage.bind(this,i));
            
            if ( i == 0 )
            {
                this.page_arr[i].update('<div class="dot_color quote_dot_color sprite_main">&nbsp;</div>');
                
                this.page_arr[i].setStyle(
                {
                    cursor:'default',
                    textAlign:'center'
                });
            }
            else
            {
                this.page_arr[i].update('<div class="mm_grey_dot sprite_main">&nbsp;</div>');
                
                this.page_arr[i].setStyle(
                {
                    cursor:'pointer',
                    textAlign:'center'
                });
            }
            
            nav_row.insert(this.page_arr[i], {position:'bottom'});
            //imgLinkArr[i] = $('landing_block_' + (i+1)).readAttribute('src');
            
        }
        //alert(imgLinkArr[0] + " : " + imgLinkArr[1] + " : " + imgLinkArr[2]);
        this.right_nav = new Element('td', {style:'cursor:pointer;text-align:center'}).update('<div class="sprite_main quote_block_scroll_middle_enabled_right">&nbsp</div>');
        nav_row.insert(this.right_nav, {position:'bottom'});
        
        this.left_nav.observe('click', this.scrollLeft.bind(this));
        this.right_nav.observe('click', this.scrollRight.bind(this));
        
        this.imgLink1 = $('landing_block_11').readAttribute('src');
        this.imgLinkCurrent = $('landing_block_11').readAttribute('src');
        this.imgLink2 = $('landing_block_22').readAttribute('src');
        this.imgLink3 = $('landing_block_33').readAttribute('src');
        
        $('go_to_article_button_photo').href = $('landing_block_11').readAttribute('src');
    },
        
    
    gotoPage: function(page_num)
    {
        if ( this.current == page_num || this.sliding )
        {
            return;
        }
        
        this.pagenum = page_num+1;
        if (this.pagenum == 1)
        {
            this.imgLinkCurrent = this.imgLink1;
        }
        else if (this.pagenum == 2)
        {
            this.imgLinkCurrent = this.imgLink2;
        }
        else if (this.pagenum == 3)
        {
            this.imgLinkCurrent = this.imgLink3;
        }
        $('go_to_article_button_photo').writeAttribute(
        {
            href:this.imgLinkCurrent
        });
        
        
        this.page_arr[page_num].down('div').removeClassName('mm_grey_dot');
        this.page_arr[page_num].down('div').addClassName('dot_color quote_dot_color');
  
        
        this.page_arr[page_num].setStyle(
        {
            cursor:'default'
        });
        
        
        this.page_arr[this.current].down('div').removeClassName('dot_color quote_dot_color');
        this.page_arr[this.current].down('div').addClassName('mm_grey_dot');
        
        this.page_arr[this.current].setStyle(
        {
            cursor:'pointer'
        });
        
        if ( page_num > this.current )
        {
            this.sliding = true;
            this.current_pos -= this.shift_amount * this.block_width * (page_num-this.current);
            
            new Effect.Move(this.photo_slider, {x:-this.shift_amount*this.block_width*(page_num-this.current), duration: 0.5, mode: 'relative', afterFinish:this.doneSliding.bind(this)});
            
            this.current = page_num;
        }
        else
        {
            this.sliding = true;
            this.current_pos += this.shift_amount * this.block_width * (this.current - page_num);
            
            new Effect.Move(this.photo_slider, {x:this.shift_amount*this.block_width*(this.current - page_num), duration: 0.5, mode: 'relative', afterFinish:this.doneSliding.bind(this)});
            
            this.current = page_num;
        }
        
        if ( this.current_pos < 0 )
        {
            
            
            this.left_nav.down('div').removeClassName('quote_block_scroll_middle_disabled_left');
            this.left_nav.down('div').addClassName('quote_block_scroll_middle_enabled_left');
            
            this.left_nav.setStyle(
            {
                cursor:'pointer',
                width:'35px'
            });
        }
        else
        {
            
            
            this.left_nav.down('div').removeClassName('quote_block_scroll_middle_enabled_left');
            this.left_nav.down('div').addClassName('quote_block_scroll_middle_disabled_left');
            
            
            this.left_nav.setStyle(
            {
                cursor:'default',
                width:'35px'
            });
        }
        
        if ( (this.current_pos - (this.shift_amount * this.block_width)) > -(this.num_items * this.block_width) )
        {
            
            
            this.right_nav.down('div').removeClassName('quote_block_scroll_middle_disabled_right');
            this.right_nav.down('div').addClassName('quote_block_scroll_middle_enabled_right');
            
            this.right_nav.setStyle(
            {
                cursor:'pointer'
            });
        }
        else
        {
            
            
            this.right_nav.down('div').removeClassName('quote_block_scroll_middle_enabled_right');
            this.right_nav.down('div').addClassName('quote_block_scroll_middle_disabled_right');
            
            this.right_nav.setStyle(
            {
                cursor:'default'
            });
        }
    },
    
    scrollLeft: function(event)
    {
        if ( this.current_pos == 0 || this.sliding )
        {
            return;
        }
        
        
        this.pagenum = this.current;
        if (this.pagenum == 1)
        {
            this.imgLinkCurrent = this.imgLink1;
        }
        else if (this.pagenum == 2)
        {
            this.imgLinkCurrent = this.imgLink2;
        }
        else if (this.pagenum == 3)
        {
            this.imgLinkCurrent = this.imgLink3;
        }
        $('go_to_article_button_photo').writeAttribute(
        {
            href:this.imgLinkCurrent
        });
        
        
        
        this.page_arr[this.current-1].down('div').removeClassName('mm_grey_dot');
        this.page_arr[this.current-1].down('div').addClassName('dot_color quote_dot_color');
        
        
        
        this.page_arr[this.current-1].setStyle(
        {
            cursor:'default'
        });
        
        this.page_arr[this.current].down('div').removeClassName('dot_color quote_dot_color');
        this.page_arr[this.current].down('div').addClassName('mm_grey_dot');
        
        
        this.page_arr[this.current].setStyle(
        {
            cursor:'pointer'
        });
        
        this.current -= 1;
        this.sliding = true;
        
        this.current_pos += this.shift_amount*this.block_width;
        
        new Effect.Move(this.photo_slider, {x:this.shift_amount*this.block_width, duration: 0.5, mode: 'relative', afterFinish:this.doneSliding.bind(this)});
        
        if ( this.current_pos < 0 )
        {
            
            
           this.left_nav.down('div').removeClassName('quote_block_scroll_middle_disabled_left');
            this.left_nav.down('div').addClassName('quote_block_scroll_middle_enabled_left');
            
            
            this.left_nav.setStyle(
            {
                cursor:'pointer',
                width:'35px'
            });
        }
        else
        {
            
            
            this.left_nav.down('div').removeClassName('quote_block_scroll_middle_enabled_left');
            this.left_nav.down('div').addClassName('quote_block_scroll_middle_disabled_left');
            
            this.left_nav.setStyle(
            {
                cursor:'default',
                width:'35px'
            });
        }
        
        if ( (this.current_pos - (this.shift_amount * this.block_width)) > -(this.num_items * this.block_width) )
        {
            
            
            this.right_nav.down('div').removeClassName('quote_block_scroll_middle_disabled_right');
            this.right_nav.down('div').addClassName('quote_block_scroll_middle_enabled_right');
            
            this.right_nav.setStyle(
            {
                cursor:'pointer'
            });
        }
        else
        {
            

            this.right_nav.down('div').removeClassName('quote_block_scroll_middle_enabled_right');
            this.right_nav.down('div').addClassName('quote_block_scroll_middle_disabled_right');
            
            this.right_nav.setStyle(
            {
                cursor:'default'
            });
        }
    },
    
    scrollRight: function(event)
    {
        if ( (this.current_pos - (this.shift_amount * this.block_width)) <= -(this.num_items * this.block_width) || this.sliding )
        {
            return;
        }
        
        this.pagenum = this.current+2;
        if (this.pagenum == 1)
        {
            this.imgLinkCurrent = this.imgLink1;
        }
        else if (this.pagenum == 2)
        {
            this.imgLinkCurrent = this.imgLink2;
        }
        else if (this.pagenum == 3)
        {
            this.imgLinkCurrent = this.imgLink3;
        }
        $('go_to_article_button_photo').writeAttribute(
        {
            href:this.imgLinkCurrent
        });
        
        this.page_arr[this.current+1].down('div').removeClassName('mm_grey_dot');
        this.page_arr[this.current+1].down('div').addClassName('dot_color quote_dot_color');
        
        
        
        this.page_arr[this.current+1].setStyle(
        {
            cursor:'default'
        });
        
        this.page_arr[this.current].down('div').removeClassName('dot_color quote_dot_color');
        this.page_arr[this.current].down('div').addClassName('mm_grey_dot');
        
        
        this.page_arr[this.current].setStyle(
        {
            cursor:'pointer'
        });
        
        this.current += 1;
        this.sliding = true;
        
        this.current_pos -= this.shift_amount*this.block_width;
        
        new Effect.Move(this.photo_slider, {x:-this.shift_amount*this.block_width, duration: 0.5, mode: 'relative', afterFinish:this.doneSliding.bind(this)});
        
        if ( this.current_pos < 0 )
        {
            
            
            this.left_nav.down('div').removeClassName('quote_block_scroll_middle_disabled_left');
            this.left_nav.down('div').addClassName('quote_block_scroll_middle_enabled_left');
            
            
            this.left_nav.setStyle(
            {
                cursor:'pointer',
                width:'35px'
            });
        }
        else
        {
            
            
            this.left_nav.down('div').removeClassName('topmm_block_scroll_middle_enabled_left');
            this.left_nav.down('div').addClassName('quote_block_scroll_middle_disabled_left');
            
            this.left_nav.setStyle(
            {
                cursor:'default',
                width:'35px'
            });
        }
        
        if ( (this.current_pos - (this.shift_amount * this.block_width)) > -(this.num_items * this.block_width) )
        {
            
            
            this.right_nav.down('div').removeClassName('quote_block_scroll_middle_disabled_right');
            this.right_nav.down('div').addClassName('quote_block_scroll_middle_enabled_right');
            
            this.right_nav.setStyle(
            {
                cursor:'pointer'
            });
        }
        else
        {
            
            
            this.right_nav.down('div').removeClassName('quote_block_scroll_middle_enabled_right');
            this.right_nav.down('div').addClassName('quote_block_scroll_middle_disabled_right');
            
            this.right_nav.setStyle(
            {
                cursor:'default'
            });
        }
    },
    
    doneSliding: function(event)
    {
        this.sliding = false;
    }
});