/* Here's the javascript specific to the CHEJ website */

jQuery(document).ready(function(){
	jQuery("#sidebarmain").corner();
	var bottomcorners="<div class='bottomcornercontainer'><div class='bottomcornerleft'></div><div class='bottomcornermiddle'></div><div class='bottomcornerright'></div></div>";
	jQuery("#common_footer .innershopbox").append(bottomcorners);
	jQuery("#common_footer .shopbox").corner();
	jQuery("#homeslide_button").corner("bl br");

	
	// search field 
	jQuery("#search #s").bind('focus', function(e) {searchInputLabelFocus("#search #s",searchInputLabel) });
	jQuery("#search #s").bind('blur', function(e) { searchInputLabelBlur("#search #s",searchInputLabel) });
	
	// username field 
	jQuery("#sidebarloginform #log").bind('focus', function(e) { jQuery("#sidebarloginform #log").removeClass("labeled"); });
	jQuery("#sidebarloginform #log").bind('blur', function(e) { 
		if (jQuery("#sidebarloginform #log").val()=='') jQuery("#sidebarloginform #log").addClass('labeled'); });
	
	// password field 
	jQuery("#sidebarloginform #pwd").bind('focus', function(e) { jQuery("#sidebarloginform #pwd").removeClass("labeled"); });
	jQuery("#sidebarloginform #pwd").bind('blur', function(e) { 
		if (jQuery("#sidebarloginform #pwd").val()=='') jQuery("#sidebarloginform #pwd").addClass('labeled'); });
	
	/* hide text in drop down */
	jQuery('#access .menu-item-198 a').text('');  
	
	/* hide poll title */
	jQuery('#sidebar .widget_polls-widget h2.widgettitle').text('');  
	
	/* rotate home slider */
	homeslide_play();
	jQuery("#homeslide_button #playpause").bind('click',function(e){ homeslide_togglePlayPause() });

});

// globals 
var searchInputLabel = 'search chej.org';
var homeslideInt;
var homeslide_active = 1;

function searchInputLabelFocus(ref,label) {
	if (jQuery(ref).val() == label) jQuery(ref).val('');
}
function searchInputLabelBlur(ref,label) {
	if (jQuery(ref).val() == '') jQuery(ref).val(label);
}

/* image slider */
jQuery(document).ready(function (){
	jQuery('#homeslide_button a').click(function(e){
		var integer = jQuery(this).attr('rel');
		jQuery('#homeslide_myslide .cover').animate({left:-625*(parseInt(integer)-1)})  /*----- Width of div myinnerslide (here 160) ------ */
		jQuery('#homeslide_button a').each(function(){
		jQuery(this).removeClass('active');
			if(jQuery(this).hasClass('button'+integer)){
				jQuery(this).addClass('active')}
				homeslide_pause();
				homeslide_active = integer; 
		});
	});
});
function homeslide_next() {
	// update active slide variable 
	homeslide_active_prev = homeslide_active;
	homeslide_active++;
	if (homeslide_active > 6) homeslide_active = 1;
	// move the slide 
	jQuery('#homeslide_myslide .cover').animate({left:-625*(parseInt(homeslide_active)-1)})  /*----- Width of div myinnerslide (here 160) ------ */
	// remove the bottom highlight from the current one  
	jQuery('.button'+homeslide_active_prev).removeClass('active'); jQuery(".sliderstatus").text("homeslide_active:"+homeslide_active);
	// add the bottom highlight to the new one
	jQuery('.button'+homeslide_active).addClass('active'); jQuery(".sliderstatus").text("homeslide_active:"+homeslide_active);
}
function homeslide_play() {
	homeslideInt = setInterval("homeslide_next()",7000);
	jQuery("#homeslide_button").addClass("playing");
}
function homeslide_pause() {
	clearInterval(homeslideInt);
	jQuery("#homeslide_button").removeClass("playing");
}
function homeslide_togglePlayPause() {
	if (jQuery("#homeslide_button").hasClass("playing")) homeslide_pause();
	else { homeslide_next(); homeslide_play(); }
}


