$(document).ready(function(){
	
	$("#grey_container").corner("bottom cc:#333");	
	$("#logo_row").corner("10px top");	
	
	
	//rounding the clients logos
	//$(".client_image").corner("5px");
	$(".client_image").corner("6px");
	
	
	$("#menu").fadeTo("slow", 0.65);
	
	original_size	=	0;
	size_min		=	10;
	size_max		=	24;
	change_factor	=	2;
	
	$(".font").hover(function(){
							  
							  	$(this).css("cursor", "pointer");
									$(this).css("background-color", "#FC0");
							  
							  }, function(){
								  
								  $(this).css("cursor", "default");
								  $(this).css("background-color", "#fff");
							  });
	
	
    $(".font").click(function () { 
		
		action			=	$(this).attr("action");
		
		//Get the current size
		current_size	=	$(".content").css("font-size");
		
		//record the original size
		if (original_size == 0)	original_size = current_size;
		
		
		//get rid of the "pix"
		current_size	=	str_replace("px", "", current_size);
		
		//convert the size into an int type
		current_size	=	parseInt(current_size);
		
		//set the new size to the same as the current one as a default change factor
		new_size		=	current_size;
		
		//set threasholds within which font resizing is permissable > this is the tricky part
		threashold_max	=	size_max - (current_size + change_factor);
		threashold_min	=	(current_size - change_factor) - size_min;
			
		//set the new sizes
		if(action == "increase" && threashold_max 	> 0)	new_size	=	current_size + change_factor;
		if(action == "decrease" && threashold_min 	> 0)	new_size	=	current_size - change_factor;
		if(action == "reset")								new_size	=	original_size;
		
		//now apply the new size
		$(".content *").css("font-size", new_size);
		$(".content").css("font-size", new_size);
		
		
    });
});



function str_replace(search, replace, subject, count) {
    // Replaces all occurrences of search in haystack with replace  
    // 
    // version: 905.3122
    // discuss at: http://phpjs.org/functions/str_replace
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Gabriel Paderni
    // +   improved by: Philip Peterson
    // +   improved by: Simon Willison (http://simonwillison.net)
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   bugfixed by: Anton Ongson
    // +      input by: Onno Marsman
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +    tweaked by: Onno Marsman
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   input by: Oleg Eremeev
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Oleg Eremeev
    // %          note 1: The count parameter must be passed as a string in order
    // %          note 1:  to find a global variable in which the result will be given
    // *     example 1: str_replace(' ', '.', 'Kevin van Zonneveld');
    // *     returns 1: 'Kevin.van.Zonneveld'
    // *     example 2: str_replace(['{name}', 'l'], ['hello', 'm'], '{name}, lars');
    // *     returns 2: 'hemmo, mars'
    var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0,
            f = [].concat(search),
            r = [].concat(replace),
            s = subject,
            ra = r instanceof Array, sa = s instanceof Array;
    s = [].concat(s);
    if (count) {
        this.window[count] = 0;
    }

    for (i=0, sl=s.length; i < sl; i++) {
        if (s[i] === '') {
            continue;
        }
        for (j=0, fl=f.length; j < fl; j++) {
            temp = s[i]+'';
            repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
            s[i] = (temp).split(f[j]).join(repl);
            if (count && s[i] !== temp) {
                this.window[count] += (temp.length-s[i].length)/f[j].length;}
        }
    }
    return sa ? s : s[0];
}


function show_message(message, duration){
	
	opacity = 0.9;
	if (message == '') message = "No message";
	$("#message_box").html(message);
	$("#message_box").fadeTo(0, opacity).fadeIn("slow");
	
	//0 means infinate
	if (duration != 0)	setTimeout("$('#message_box').fadeOut('slow');", duration);
}



//header language rotater
function slideSwitch() {
	var $active = $('#slideshow IMG.active');

	if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

	var $next =  $active.next().length ? $active.next() : $('#slideshow IMG:first');

	$active.addClass('last-active');

	$next.css({opacity: 0.0})
		.addClass('active')
		.animate({opacity: 1.0}, 1000, function() {
			$active.removeClass('active last-active');
		});
}

$(function() {
	setInterval( "slideSwitch()", 5000 );
});
	
	

