$(document).ready(function(){
    //MenuLeft Select
    var _url = location.href;
    _url = _url.substring(_url.indexOf('//')+2);
    _url = _url.replace(location.hostname,'');
	$('ul.mnu-left a[href='+_url+']').parent().addClass('current-page');
		
	$('label.overlabel').overlabel();
	$(".main-nav li.selected").prev().addClass("hover-prev");
	
	  $(this).prev().addClass("hover-prev");

	$('li:last-child, td:last-child , a:last-child, tr:last-child, th:last-child  ').addClass("last-child");
	$('li:first-child, td:first-child, a:first-child, tr:first-child, th:first-child ').addClass("first-child");
	$('ul.ektSitemap>li:even').addClass('clear');

	$('img[src$=.png]').fixpng();
	$('.blue-box').box_round('top-bottom');
	$('.blue-box2, .case-study, .rounded-blue-box, .blue-soft-box, .blue-soft-box2, .gris-box, .orange-button,.contact-data, .blue-box, .sign-up').box_round('default');
	$('.eq, .blue-box, .table-3cols td').equalizeCols();
	
	$(".main-nav>li").hover(
	    function(){
          $(this).addClass("hover");
	      $(this).prev().addClass("hover-prev");
    	  
        },
        function(){
		    if ( ! $(this).hasClass("selected")) {
			    $(this).prev().removeClass("hover-prev");
			    }
          $(this).removeClass("hover");	
        });
	
	var _span= document.createElement("span");
	$(".main-nav>li:first-child").prepend(_span);
	var _span2= document.createElement("span");
	$(".main-nav>li:last-child").append(_span2);
	$(".main-nav>li").each(function(){
	    var _w = $(this).width()+2;
	    $(this).find('>table').each(function(){
	        var _wt = $(this).width();
	        _wt = (_wt>_w)?_wt:_w;
	        $(this).attr('width',_wt);
	    });
	});

    $('#eventsCalendar .mv_DateCell a, #eventsCalendar .mv_DateCellWeekend a, #eventsCalendar .mv_DateCellToday a').removeAttr('onclick');

	/* search input */
	$("#txt-search").keydown( function(event) {
		if(event.keyCode == 13) {
 		
		event.preventDefault();
	 	event.stopPropagation();
		$("form").submit(function(event) {
			event.preventDefault();
		 	event.stopPropagation();
			return false;
		});
		RedirectUser();
		return false;
	 	}
	 });
	$("#btnSearch").click(function(){ RedirectUser(); });
	
	
});

/* =jQuery Plugins*/
(function($){
	/* = plug-in : overlabel */
	$.fn.overlabel = function(options){
		var opts = $.extend( {},$.fn.overlabel.defaults, options );
		var selection = this.filter('label[for]').map(function(){
				var label = $(this);
				var id = label.attr('for');
				var field = $('#'+id);
				if(!field) return;
				var o = $.meta ? $.extend( {}, opts, label.data() ) : opts;
				label.addClass(o.label_class);
				var hide_label = function(){ label.css(o.hide_css) };
				var show_label = function(){ this.value || label.css(o.show_css) };
				$(field)
					.parent().addClass(o.wrapper_class).end()
					.focus(hide_label).blur(show_label).each(hide_label).each(show_label);
				return this;
		});
		return opts.filter ? selection : selection.end();
	};
	$.fn.overlabel.defaults = {
		label_class: 'overlabel-apply',
		wrapper_class: 'overlabel-wrapper',
		hide_css: { 'display': 'none' },
		show_css: { 'display': 'block' },
		filter: false
	};
	/* =plug-in : fix-png */
	$.fn.fixpng = function(){
		var hack = {
			isOldIE: $.browser.msie && $.browser.version < 7,
			filter: function(src){ return "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='scale',src='"+src+"');"; }
		};
		return this.each(function(){
			if(hack.isOldIE){
				var $$=$(this);
				if($$.attr('src')){
					var span = document.createElement('span');
					$(span).attr({
						id: $$.attr('id'), className: $$.attr('class')
					});
					$(span).css({
						display: 'inline-block', width: $$.width(), height: $$.height(), filter: hack.filter($$.attr('src')), float: $$.attr('align')=='left'?'left':($$.attr('align')=='right'?'right':'none')
					});
					this.outerHTML = span.outerHTML;
				}
			}
		});
	};
	$.fn.box_round = function(options) {
		var type = options ? options : 'default'; /*default, only-top, only-bottom*/
		return this.each(function() {
		if (type == 'default' || type == 'only-top') {
		var _tleft = document.createElement("span"); _tleft.className = "corner tl";
		$(this).prepend(_tleft);
		}
		if (type == 'default' || type == 'only-top') {
		var _tright = document.createElement("span"); _tright.className = "corner tr";
		$(this).prepend(_tright);
		}
		if (type == 'default' || type == 'only-bottom') {
		var _bleft = document.createElement("span"); _bleft.className = "corner bl";
		$(this).prepend(_bleft);
		}
		if (type == 'default' || type == 'only-bottom') {
		var _bright = document.createElement("span"); _bright.className = "corner br";
		$(this).prepend(_bright);
		}
		if (type == 'top-bottom') {
		var _bottom = document.createElement("span"); _bottom.className = "bottom";
		var _top = document.createElement("span"); _top.className = "top";
		$(this).prepend(_bottom, _top);
		}
		if (type == 'title' || type == 'title-left') {
		var _bleft = document.createElement("span"); _bleft.className = "left-title";
		$(this).prepend(_bleft);
		}
		if (type == 'title' || type == 'title-right') {
		var _bright = document.createElement("span"); _bright.className = "right-title";$(this).append(_bright);}});
	};
	/* =plug-in : equal-heights */
	$.fn.equalizeCols = function(){
		var height = 0,
			 reset = $.browser.msie ? "1%" : "auto";
		return this
			.css("height", reset)
			.each(function() {
				height = Math.max(height, $(this).outerHeight(true));
			})
			.css("height", height)
			.each(function() {
				var h = $(this).outerHeight(true);
				if (h > height) {
					$(this).css("height", height - (h - height));
				};
			});
	};
})(jQuery);

function RedirectUser()
{
    if($('#txt-search').val() != '')
	{
	    var searchUrl = '/Search.aspx?q=' + $('#txt-search').val();
		window.location.href = searchUrl;
    }
}

var thisVal;
var isLogged;
function hasUserLoggedIn()
{
    if(thisVal == 1)
    {
        document.getElementById('divPremimum').style.display = "block";
    }
    else
    {
        document.getElementById('divPremimum').style.display = "none";
    }

    if(isLogged == 1)
    {
        document.getElementById('liPremimumContent').style.display = "block";
        document.getElementById('liContact').className = "";
    }
    else
    {
        document.getElementById('liPremimumContent').style.display = "none";
        document.getElementById('liContact').className = "nobgr";
    }
}
