$(document).ready(function(){	

/*$(function(){
	$('a[href*=#]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
		&& location.hostname == this.hostname) {
		var $target = $(this.hash);
		$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
		if ($target.length) {
		var targetOffset = $target.offset().top;
		$('html,body').animate({scrollTop: targetOffset}, 1000);
		return false;
		}}
	});
 });

*/
 $.fn.positionOn = function(element, align) {
   return this.each(function() {
     var target   = $(this);
     var position = element.position();
     var x      = position.left; 
     var y      = position.top;
      if(align == 'right') {
       x -= (target.outerWidth() - element.outerWidth());
     } else if(align == 'center') {
       x -= target.outerWidth() / 2 - element.outerWidth() / 2;
     }
      target.css({
       position: 'absolute',
       zIndex:   5000,
       top:      y, 
       left:     x
     });
   });
 };

 $('.right_side_tabs .showTabMenu').positionOn($('.right_side_tabs .right_tabs_more'), 'right')


if($(".columnizer").length>0){$('.columnizer').columnize({ columns: 2 });}



$("p:empty").remove();

$(".newsBlock").each(function(){ 	$(this).find('p:not(:first)').remove();  });


$(function() {
	$.fn.mysort = function(){ this.sortable({
	axis: 'y',
	forceHelperSize: true,
    forcePlaceholderSize: true,
    opacity: 0.8,
	connectWith: '.news_wrapper',
    placeholder: 'placeholder',
	update: function()  {
			var ser = $(this).sortable('toArray');
			$.cookie('sortsave', ser);
				}
		}).show();
	}
	if($.cookie('sortsave')){
		var pos = $.cookie('sortsave').split(',');
		$(pos).each(function(i){
		$(".news_wrapper").append($('.news_wrapper div#'+pos[i]+'')).mysort();	  
		});
	
	}
	else {
	
		$(".news_wrapper").mysort();
		
	}
	
});

$(function(){ $('.news_wrap').equalHeights(); });

$("img.thumb").each(function(){
        var desc =  $(this).attr("desc");
        $(this).wrap('<div class="thumb_wrapper" />').wrap('<div class="border_wrapper" />').after(function() {
        if (typeof desc !== 'undefined' && desc !== false) {
		return '<div class="description">'+ desc +'</div>';
		}
		else
		{return '<div class="empty"></div>';}
	});
});


$(".certTabs li").hover(function(){
	var width = $(this).outerWidth();
	$(this).find(".showTabMenu").css("min-width",width).show();
	},function(){
	$(this).find(".showTabMenu").hide();
});


$('.contentTop div.contentTopBlock:first').css({float: 'left', margin: '0 1.5% 0 0'})
$('.contentTop div.contentTopBlock:last').css("float", "right");

$('.certContent ul li').wrapInner($('<p/>'));
$("#browser p").contents().unwrap();


$("a.modal, a.modal_carousel, a.zoom1").colorbox({transition:"fade",rel:"group", maxWidth:"95%",maxHeight:"95%"});
$("a.inline").colorbox({inline:true});
$(".iframe").colorbox({width:"95%", height:"90%", iframe:true});
/*$(document).bind('cbox_complete', function(){
    $('#cboxLoadedContent').append("<div id='protect' />");

}); */


$('table.nice tr:nth-child(odd)').addClass('odd');
$("#browser").treeview({animated: "fast",collapsed: true,unique: true});

$(".container").addClass("hidden");
$(".bottomTabsText").html($(".container div:first").html()).addClass("violetTab");

$("#rs").carouFredSel({
		items : 3,
		scroll: 3,
		circular	: false,
		infinite	: false,
		auto 		: false,
		prev : {	
			button	: "#rs_prev",
			easing		: "easeOutBack",
			key		: "left"
		},
		next : { 
			button	: "#rs_next",
			easing		: "easeOutBack",
			key		: "right"
		},
		pagination  : "#rs_pag"
});
$("#vs").carouFredSel({
		items : 3,
		scroll: 3,
		circular	: false,
		infinite	: false,
		auto 		: false,
		prev : {	
			button	: "#vs_prev",
			easing		: "easeOutBack",
			key		: "left"
		},
		next : { 
			button	: "#vs_next",
			easing		: "easeOutBack",
			key		: "right"
		},
		pagination  : "#vs_pag"
});
$("#aps").carouFredSel({
		items : 3,
		scroll: 3,
		circular	: false,
		infinite	: false,
		auto 		: false,
		prev : {	
			button	: "#aps_prev",
			easing		: "easeOutBack",
			key		: "left"
		},
		next : { 
			button	: "#aps_next",
			easing		: "easeOutBack",
			key		: "right"
		},
		pagination  : "#aps_pag"
});
$("#other").carouFredSel({
		items : 3,
		scroll: 3,
		circular	: false,
		infinite	: false,
		auto 		: false,
		prev : {	
			button	: "#other_prev",
			easing		: "easeOutBack",
			key		: "left"
		},
		next : { 
			button	: "#other_next",
			easing		: "easeOutBack",
			key		: "right"
		},
		pagination  : "#other_pag"
});
$("#all").carouFredSel({
		items : 3,
		scroll: 3,
		circular	: false,
		infinite	: false,
		auto 		: false,
		prev : {	
			button	: "#all_prev",
			easing		: "easeOutBack",
			key		: "left"
		},
		next : { 
			button	: "#all_next",
			easing		: "easeOutBack",
			key		: "right"
		},
		pagination  : "#all_pag"
});
$("#carousel").show();
$("#carousel").carouFredSel({
	items : 4,
	scroll: {
						items 		: 4,
						duration	: 400,
						easing		: "linear"
					},
	auto : false,
	pagination	: "#carousel_pag"
});


var width = $(".caroufredsel_wrapper").width() / 3-30;
$(".newsBlock").width(width);

/*var width_thumbs = $(".caroufredsel_wrapper").width() / 4-1;
$(".caroufredsel_wrapper a").width(width_thumbs);
$(".caroufredsel_wrapper a:nth-child(4n)").css("border-right","none");*/

if($(".bottomTabsText").length>0){var jpane = $('.bottomTabsText').jScrollPane();}
$(".bottomTabs a").live("click",function(){
	var jpapi = jpane.data('jsp');
	var el = $(this);
   $(".bottomTabs span").parent().html("<a href=\"#\">"+$(".bottomTabs span").html()+"</a>");
   $(".jspPane").html($("#"+el.parent().attr("class")).html());
   $(".bottomTabsText").removeClass("violetTab").removeClass("greenTab").removeClass("orangeTab").removeClass("blueTab");
   $(".bottomTabsText").addClass(el.parent().attr("class"));
   jpapi.reinitialise();
   el.parent().html("<span>"+el.html()+"</span>");
   return false;
});

});
