function scrollbarWidth() {
    var div = $('<div style="width:50px;height:50px;overflow:hidden;position:absolute;top:-200px;left:-200px;"><div style="height:100px;"></div>');
    // Append our div, do our calculation and then remove it
    $('body').append(div);
    var w1 = $('div', div).innerWidth();
    div.css('overflow-y', 'scroll');
    var w2 = $('div', div).innerWidth();
    $(div).remove();
    return (w1 - w2);
}	





function isIE() {
	return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
}

function rw_trigger(height1, height2) {
	var height1 = $("#main-content-div").height();
	var height2 = $("#right-wraper").outerHeight();
	
	if(height2 < height1){
	
		var p = (height1 - height2) + 65;
		//return $("#right-wraper").height(height1);
		return $("#right-content-div").css('padding-bottom', p+'px');
	}
	else return false;
}

// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////



$(document).ready(function(){


/* --------------- PAGE BUTTON ----------------------------- */

if($('.button')){
	$('.button').wrapInner('<span class="inner_blue"></span>');
	
	if(!$.browser.msie) {
		$('.inner_blue').corner("10px");
	}	
}


/* --------------------------------------------------------- */


	var site = "";
	
	if ($.browser.msie && $.browser.version.substr(0,1)<8) {
		
		/*
		$("head").append("<link>");
    	css = $("head").children(":last");
    	css.attr({
     		rel:  "stylesheet",
     		type: "text/css",
	    	href: "/public/settings/main_menu_all_ie.css",
	    	media: "screen"
        });
		*/
		$(".acc-content ul").css("float", "left");

    }

	

// ////////////////////////////////////////////// MAIN MENU //////////////////////////////////////////////////
	
	
	
/*	
    $('ul#menu-main-links li').hover(
    
    	function (){
    		//var id = 'div#' + $(this).attr('id');
    		//rel = id + '.sub-menu';
    		//alert(rel);
    		$('.top-branch',this).show();
    		
    		$('ul',this).toggleClass('visible');
    		$('.bottom-branch',this).show();
    		
    		//$(id+'.top-branch').addClass('opened');
    		//$(id+'.sub-menu-links').addClass('opened');
    		//var id = 'span#' + $(this).attr('rel');
    		//alert(rel);
    		//alert(rel);
    		//$('span', this).addClass('current');
    		
    		
    		//alert("sdfsdf");
    	},
    	function(){
    		$('.top-branch',this).hide();
    		
    		
    		
    	//	$('div', this).removeClass('opened');
    	//	$('*').removeClass('current');
    	}
	);
 */   	
	
	//$("#left-menu-links").accordion({ navigation: true });
	
	//$('.acc-image').corner();
	
// ///////////////////////////////////////////// LEFT MENU FUNCTIONS //////////////////////////////////////
	
	$("ul.left_sub_menu li:last-child").addClass('last');
	
	
	var opened = [];
	var clicked;
	//$('.holder').css('height', '58pt');
	
	if($('.holder').hasClass('opened')) {
				opened.push($('.opened',this).attr('id'));
				//alert("sfsd");
	}
	//alert(opened);
	var opened = [];
	var clicked;
	//$('.holder').css('height', '58pt');
	
	if($('.holder').hasClass('opened')) {
				opened.push($('.opened',this).attr('id'));
				//alert("sfsd");
	}
	//alert(opened);
	
	$('.holder .grey-bg').hover(
		function(){
			
			//$(this).addClass('current');
			
			$('div.bg-holder', this).css('opacity', '0.3');
			$('div.bg-holder', this).css('background-position', '-166px 0');
			$('div.bg-holder', this).animate({ opacity:1 }, 250);
			
			$('div.mask', this).addClass('orange');
		},
		function(){
			//$(this).removeClass('current');
		
			$('div.bg-holder', this).css('opacity', '0.3');
			$('div.bg-holder', this).css('background-position', '0 0');
			$('div.bg-holder', this).animate({ opacity:1 }, 250);
			
			$('div.mask', this).removeClass('orange');
		}
	);
	
	
	//$('.holder .grey-bg').hover(
	$('.holder .grey-bg').click(
	
	function(){
		
		var parent = $(this).parent();			// $('.holder');

		// hiding
				
				
				//if ($('.acc-content').hasClass('opened')) {
				//	$('.acc-content')slideUp('slow');
				//}
			if($('.acc-content', parent).hasClass('opened')) {
				$('div.mask').addClass('shown');
				
				/* 1)all opened grey close
				$(".acc-content.opened").slideUp("slow", function(){
					$('.acc-title a').removeClass('current');
			
					$('.grey-bg', this).removeClass('current');
					$('.acc-content').removeClass("opened");
				
				});
				end of 1) */
				
				$(".acc-content", parent).slideUp("slow", function(){
					$('.acc-title a', parent).removeClass('current');
			
					$('.grey-bg', this).removeClass('current');
					$('.acc-content', parent).removeClass("opened");
				
				});
			}	
			else {
				// expanding
				if($('.acc-content ul', parent).length) {
					$('div.mask', parent).removeClass('shown'); 
					//parent.css('height', '100%');
					$('.acc-content', parent).slideDown('slow', function(){
						$('.acc-title a', parent).addClass('current');
				
						$('.acc-content', parent).addClass("opened");
					});
				
				}
				/*
				parent.animate({
					//height: "100%"
					height: parent.css('height', '100%')
					
				},
				{
					duration: 500,
					queue: true
				}
				);
				*/
				
			
			
			
			}//, // else
				/*
				
				$('div.mask').addClass('shown');
				
				
				$(".acc-content.opened").slideUp("slow", function(){
					$('.acc-title a').removeClass('current');
			
					$('.grey-bg', this).removeClass('current');
					$('.acc-content').removeClass("opened");
				
				});
				
			*/
			}
			//$('.acc-content', parent).slideUp('slow');
				//$('.holder').css('height', '58pt');
				//$(this).siblings('ul').slideToggle('slow');
				/*
				$('.holder').animate({
					height: '58pt'
				}, { duration: 500, queue: true });
			*/
				//$('.acc-title a').removeClass('current');
			
				//$('.grey-bg', this).removeClass('current');
			
				
			
				//$('img.mask', this).addClass('shown');	
		
		
		
		/*
		// expanding
			if($('.acc-content ul', parent).length) {
				$('div.mask', parent).removeClass('shown'); 
				//parent.css('height', '100%');
				$('.acc-content', parent).slideDown('slow', function(){
					$('.acc-title a', parent).addClass('current');
				
					$('.acc-content', parent).addClass("opened");
				});
				
			}
				/*
				parent.animate({
					//height: "100%"
					height: parent.css('height', '100%')
					
				},
				{
					duration: 500,
					queue: true
				}
				);
				*/
				
			
			
			
		//}//,
		
	//function () {
		
			// alert(opened);
		//var parent = $(this).parent();			// $('.holder');
		
		
	//}
	); // hover '.holder .grey-bg'
		
	

// /////////////////////////////////////////////////////// NEWS ////////////////////////////////////////////    
    
	if($("li.li-news-ajax").length) {
		$("a.news-ajax").click(function(){
			//alert("sadfsdf");
			//$("a", this).click(function(){ return false; });
			//var parent = $($(this)+":parent");
			var parent = $(this).parent();
			
			

			//var rel = parent.attr("id");
			var href = $(this).attr("href");
			
			//alert(rel);

			
			$.ajax({
		
    			type: "GET",
    			url: href,
    			success: function(j){
     //alert(j);
    				parent.find('span.ajax-news-content').html(j);			// load the content in the contianer
    				parent.find('span.news-close-btn').show();				// show the close button
    				$("#loading").html("");
					rw_trigger();
   				}, // success
   				beforeSend: function(){ $("#loading").html("<img src='/public/images/ajax-loader.gif' title='loading' />"); }
 			});
			
			return false;
		});
		
		$("span.news-close-btn").click(function(){
			
			$(this).parent().find('span.ajax-news-content').html("");			// 
			$(this).hide();
		});
		
	}
	
	if($.isFunction($.fn.corner)) {
		if($('.corner').length>0) {
			$('.corner').corner("20px");
		}
	}
	
	



}); // document.ready
