	
	/* hide the panels first */
jQuery(function($){
	$("#blogposts").hide();
    $("#newsposts").hide();
	$("#frontpagemore").hide();
	$("#widepagemore").hide();
	$("#youtubecontainer").hide();
});

/* set the easing */
jQuery.easing.def = "easeOutSine"; // this can change the easing style

/* add the cycle function */
jQuery(function($){
    $('#s4').after('<div id="nav" class="nav">').cycle({
        fx: 'scrollLeft',
        speed: 'slow',
        timeout: 0,
        pager: '#nav'
    });
});

/* create the function to toggle the blog slider */

jQuery(function($){
    $(".openBlogStories").bind('click', function(){
        // animate the blocks
        $('#blogposts').animate({
            height: 'toggle'
        }, 1000, function(){
            // change the text
            changeText($('.openBlogStories'));
        });
        
        
    });
});

/* create the function to toggle the news slider */

jQuery(function($){
    $(".openNewsStories").bind('click', function(){
        $('#newsposts').animate({
            height: 'toggle'
        }, 1000, function(){
            changeText($('.openNewsStories'));
        });
    });
});

/* create the function to toggle the front page more */

jQuery(function($){
    $(".openFrontPageMore").bind('click', function(){
        $('#frontpagemore').animate({
            height: 'toggle'
        }, 1000, function(){
            changeHomeMoreText($('.openFrontPageMore'));
        });
    });
});

jQuery(function($){
    $(".openFrontPageMore").bind('click', function(){
        $('#widepagemore').animate({
            height: 'toggle'
        }, 1000, function(){
            changeHomeMoreText($('.openFrontPageMore'));
        });
    });
});

jQuery(function($){
    $(".openYouTube").bind('click', function(){
        $('#youtubecontainer').animate({
            height: 'toggle'
        }, 1000, function(){
            changeHomeGalleryText($('.openYouTube'));
        });
    });
});

/* function to change the text */
/* it takes an object ie.the openNewsStories element and checks what the object text currently is */
/* if its 'open' it changes it to 'close' and vice versa */

function changeText(obj){
	
	// need to call jQuery.trim to make sure there's no whitepsace at the beginning of the element text //
    if (jQuery.trim(obj.text()).search(/Open Stories/i) != -1) { // REGEX I hate it!!
        var textToChange = "Close Stories";
    }
    else {
        var textToChange = "Open Stories";
    }
	obj.each(function(index) {
    $(this).text(textToChange);
  });

}

/* function to change the text for main post content */
function changeHomeMoreText(obj){
	
	// need to call jQuery.trim to make sure there's no whitepsace at the beginning of the element text //
    if (jQuery.trim(obj.text()).search(/> Close/i) != -1) { // REGEX I hate it!!
        var textToChange = "> Read More";
    }
    else {
        var textToChange = "> Close";
    }
	obj.each(function(index) {
    $(this).text(textToChange);
  });

}

/* function to change the text for video post content */
function changeHomeGalleryText(obj){
	
	// need to call jQuery.trim to make sure there's no whitepsace at the beginning of the element text //
    if (jQuery.trim(obj.text()).search(/> Close/i) != -1) { // REGEX I hate it!!
        var textToChange = "> Show Videos";
    }
    else {
        var textToChange = "Close";
    }
	obj.each(function(index) {
    $(this).text(textToChange);
  });

}
