$(document).ready( function() {
	var base_path = "images/";
	var random_image = ["rhi-emblem.png", "rhi-emblem2.png", "rhi-emblem3.png"];
	var image_index = Math.floor(Math.random() * random_image.length);
	
	$("#rhi-emblem").attr("src", base_path + random_image[image_index]);
	
	$("#videotabs").tabs();
	$("ul.menu ul:has(li)").not('.openme').hide();
	$(".home .enews-signup").hide();
	$(".togglesignup").click(function(){
		
		$(".enews-signup").slideToggle();
		$(this).children("a").toggleClass("opened");
		return false;
		
	});
	
	
	
	$("ul.menu a").click( function() {
		var nextElement = $(this).next();
		var prevElement = $(this).parent();
		var clickedElement = $(this);

		if ( prevElement.is('li') ) {
			prevElement.siblings('li').children('ul').slideUp();
		}

		if ( nextElement.is('ul') ) {
			nextElement.toggleClass('opened').slideToggle('fast');
		}
		
		if($('ul', this.parentNode).length){
			return false;
			clickedElement.toggleClass('opened');
			}
		else
			return true;
	});
	
	$('li#latest').addClass('active');
	if ($('li#latest ul').length){
		
		var scroll_wrapper_width = $('li#latest .scroll_wrapper').outerWidth();
		var list_width = $('li#latest ul').outerWidth();
		var scroll_interval = false;
		var list = $('li#latest ul')[0];
		
		$('li#latest ul').css({
			'left': scroll_wrapper_width + 'px'
			});
		
		var anim = function(){
			var current_left = parseInt(list.style.left);
			scroll_interval = setInterval(function(){
				current_left -= 2;
				if(current_left < -list_width)
					current_left = scroll_wrapper_width;
				list.style.left = current_left +'px';
				}, 50);
			}
		anim();
		
		$('li#latest a').mouseover(function(){
			clearInterval(scroll_interval);
			});
		
		$('li#latest a').mouseout(function(){
			anim();
			});
		
	}

	/*$("li.togglesignup").click( function() {
		$(".enews-signup").slideToggle();
		$(this).children("a").toggleClass("opened");

		return false;
	});*/

	var browser=navigator.appName;
	var b_version=navigator.appVersion;
	var version=parseFloat(b_version);

	if ( b_version.indexOf('Safari') > -1 ) {
		// compute width
		var total = $('#content').width()-$('#lside').width()-$('#rside').width()-35;
		$('#main').width(total);
	}

	// cycle testimonials
	if ( $('#testimonials-box ul').length ) {
		$('#testimonials-box ul').cycle({
			timeout: 15000 // cycle at 15 seconds
		});
	}

	/*// take care of default input values
	$('input[type=text]').focus(function(){
		var currentVal = $(this).val();										// Read initial field value
		$(this).val('');														// Clear initial value

		$(this).blur(function(){
			var getNewVal = $(this).val();										// Read new input value
			if ( getNewVal == '' || getNewVal == ' ' ) {
				$(this).val(currentVal);										// Switch to initial value
			}
		});
	});*/

	// print page
	$('.print').click(function(){
		window.print();
		return false;
	});

	
	/*
	$(window).resize(function(){
		
		SetBaseFontSize2();
		
	});
	*/
	
	// selects
	if ($('select.go').length ) {
	
		$('select.go').hide();

		if ( $.cookie('jump') != null && $.cookie('jump') != '' && $.cookie('jump') != ' ' ) {
			$('select#jump option[value='+$.cookie('jump')+']').attr('selected','selected');
			$('#'+$.cookie('jump')).show();
		}

		var current_select = false;
		$('select#jump').change(function(){
			
			var value = $('option:selected', this).val();
			$.cookie('jump', value);
			
			if(value == '#Partners#'){
				window.location.href = '/international/Partners/';
			} else {
				if(value){
					$('select#'+ value).fadeIn();
					$('.label_for_second_jump').fadeIn();
					
					if(current_select)
						$('select#'+ current_select).fadeOut();
					current_select = value;
				} else {
					if(current_select){
						$('.label_for_second_jump').fadeOut();
						$('select#'+ current_select).fadeOut();
						}
					current_select = false;
					}
				}
		});

		$('select.go').change(function(){
			if ( $('option:selected', this).val() != '' && $('option:selected', this).val() != ' ' && $('option:selected', this).val() != '#' ) {
				window.location.href = $('option:selected', this).val();
			}
		});
		
		$('select').focus(function(){
			$('.label_opt', this).css({'display': 'none'});
		});
		
		$('select').blur(function(){
			$('.label_opt', this).css({'display': 'block'});
		});
	}
	
	SetBaseFontSize2();
	
	/*$(".montage_wrapper select").mouseover(function(){
        $(this)
            .data("origWidth", $(this).css("width"))
            .css("width", "auto");
    }).mouseout(function(){
        $(this).css("width", $(this).data("origWidth"));
    });*/
	
});

function fixSafari(){
	var browser=navigator.appName;
	var b_version=navigator.appVersion;
	var version=parseFloat(b_version);

	if ( b_version.indexOf('Safari') > -1 ) {
		// compute width
		var total = $('#content').width()-$('#lside').width()-$('#rside').width()-35;
		$('#main').width(total);
	}
}

function popup(mypage,myname,w,h){
	winl = (screen.width-w)/2;
	wint = (screen.height-h)/2;
	settings='height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=no,toolbar=no';
	try {
		window.open(mypage,myname,settings);
	} catch(err) {
		alert('Please remove any popup blockers!');
	}
}

function SetBaseFontSize2(){
		if (window.innerWidth) {
			 width = window.innerWidth;
			 height = window.innerHeight;
		} else {
			if (document.documentElement.clientWidth) {
				if (document.documentElement.clientWidth > 0) {
					prefix = document.documentElement;
				} else {
			 		prefix = document.body;
				}
			} else {
				prefix = document.body;
			}

			width = prefix.clientWidth;
			height = prefix.clientHeight;
		}

		WidthSize = width / 1150;
		HeightSize = height / 688;
		BaseFontSize = ((WidthSize < HeightSize) ? WidthSize  : HeightSize) * 140;
//		alert ("Width : " + width + "px; " + "BaseFontSize : " + BaseFontSize + "%");

		if (BaseFontSize < 100) {
			BaseFontSize = 100;
		}
		
		document.body.style.fontSize = '129%';
		//document.body.style.fontSize = BaseFontSize + '%';
		
		return false;
		
		/*
		if(width < 960 + 100){
			$('#container').addClass('no_margins');
			}
		else{
			$('#container').removeClass('no_margins');
			}
		
		if(!document.body){
			var newPageWidth;
			if ( width < 954 ) {
				newPageWidth = '954px; min-width:954px;';
			} else {
				newPageWidth = '100%;';
			}
			document.writeln ("<style type='text/css'>")
			document.writeln ("body {width:"+newPageWidth+"; font-family: Tahoma, 'Trebuchet MS', Verdana, sans-serif}")
			document.writeln ("body {font-size: " + BaseFontSize + "%}")
			document.writeln ("<\/style>")
			 alert ("Document.Writeln ()s complete ...") 
			}
		else {
			if ( width < 954 ) {
				newPageWidth = '';
				document.body.style.width = '954px';
				document.body.style.minWidth = '954px';
			} else {
				document.body.style.width = '100%';
			}
			
			}
			*/
}