swfobject.registerObject("stage_flash", "9.0.0");

jQuery.noConflict();

jQuery(document).ready(function() {


// initialize homepage flash



// Scrolling Box

// $('#newsteaser').prepend('<img src="images/scroll_left.png" id="buttleft" style="display: none" />').append('<img src="images/scroll_right.png" id="buttright" />');

jQuery('#newsteaser').prepend('<div id="buttleft" style="display: none" />').append('<div id="buttright" />');



justscrolling = false;
autoscroll = false;
container = jQuery('#newsteaser .scrollContainer');
adjust = getposition();
var panelcount = jQuery('#newsteaser .panel').length;
var panelwidth = jQuery('#newsteaser .panel').width();
jQuery(container).width(panelcount * panelwidth);
visiblecontainer = (panelcount-2) * panelwidth

jQuery('#buttright').click(function(){
 autoscroll = false;
 jQuery('#buttleft').stop();
 if (justscrolling == false ) { scrollright(panelwidth); }
});

jQuery('#buttleft').click(function(){
 autoscroll = false;
 jQuery('#buttleft').stop();
 if (justscrolling == false ) { scrollleft(panelwidth); }
});

startanimate(panelwidth);


});



function scrollright(width) {
 var currpos = getposition();
 var newpos = parseInt(currpos) - parseInt(width);
 justscrolling = true;
 jQuery(container).animate({left: newpos}, 'slow', function(){
 showhide(newpos);
 justscrolling = false;
 });
}

function scrollleft(width) {
 var currpos = getposition();
 var newpos = parseInt(currpos) + parseInt(width);
 justscrolling = true;
 jQuery(container).animate({left: newpos}, 'slow', function(){
 showhide(newpos);
 justscrolling = false;
 });
}

function getposition() {
 var currpos = jQuery('#newsteaser .scrollContainer').css('left');
 currpos = currpos.substring(0, currpos.length-2)
 return parseInt(currpos);
}

function showhide(position) {
 if (position >= adjust) {
 jQuery('#buttleft').hide();
 } else {
 jQuery('#buttleft').show();
 }
 if (position <= -(visiblecontainer)+adjust) {
 jQuery('#buttright').hide();
 autoscroll = false;
 jQuery('#buttleft').stop();
 } else {
 jQuery('#buttright').show();
 }
}

function startanimate(width){
 jQuery('#buttleft').animate({top: 0}, 3000, "swing", function(){
 if (autoscroll == true) {
 scrollright(width);
 startanimate(width);
 } else {
 jQuery('#buttleft').stop();
 }
 });
}