var siteUrl = '';
var current = 1;
var currentLink=null;
var canDrop = 1;
$ = jQuery;
function drops_show(){
    $(this).addClass('show');$(this).removeClass('with-js');
    if ($(this).parent().hasClass('menu')) {
        if($(this).children().length > 1) {
                canDrop = 1;
            } else {
                canDrop = 0
            }
    }
    console.log(canDrop+' + '+$(this).children().html());
}
function drops_hide(){
    if (canDrop == 1) {
        $(this).removeClass('show');$(this).addClass('with-js');
        console.log('dropping');
    }
    console.log($(this).children().html());
}
$(document).ready(function () {

	$(".menu-left-menu-container li").hoverIntent({
		interval: 150,
		over: drops_show,
		timeout: 500,
		out: drops_hide
	});
	$(".menu-left-menu-container li").addClass('with-js');




    // custom combos
    $(".combo p span select").change(function () {
        $(this).parent().parent().parent().find("div span:first").html($(this).val());
    });

    // show sub-menu selection for sub-pages
    $(".current-menu-parent").parent().show();
	$(".current-menu-parent").parent().parent().addClass("current-menu-ancestor");

	//
    $('.bottom').append($('#temp').children());
    if ($('#googleMap').length > 0) {
        $('.c2 .img').html($('#googleMap'));
    }
    // capabilities
    $(".item").hover(
    function () {
        set_btn_state($(this).find("img")[0], true);
        $(this).addClass("hover");
    }, function () {
        if (current != $(this).attr('role')) {
            set_btn_state($(this).find("img")[0], false);
            $(this).removeClass("hover");
        }
    });
	
	$(".block ul li a").click(function(){
		var id = $(this).attr("rel");
		
		if ($(this)!=currentLink){
			if (currentLink!=null) {
				currentLink.removeClass("hover");
			}
			
			$(this).addClass("hover");
			
			var data = {
				action: 'get_post',
				post: id
			};
			$.get(adminAjaxURL, data, function(response) {
					jQuery('#dinamicText').html(response);
			});
			
			currentLink = $(this);
		}
	});
});


function set_btn_state(obj, mode) {
	if (obj) {
		var s = $(obj).attr("src");
		var base_url = s.substring(0, s.lastIndexOf("_"));
		$(obj).attr("src", base_url + '_' + (mode ? "hover.jpg" : "normal.jpg"));
	}
}


function changeItem(newPost) {
    if ($('.hover').length > 1) {
        var id;
        $('.hover').each(function () {
            var val = $(this).attr('role');
            $('#thumb' + val).removeClass("hover");
            set_btn_state($('#thumb' + val).find("img")[0], false);
            $('#thumb_content_' + val).hide();
            if (val != id) id = val;
        });
    }
    current = newPost;
    $('#thumb' + newPost).addClass("hover");
    set_btn_state($('#thumb' + newPost).find("img")[0], true);
    $('#thumb_content_' + newPost).show();
}
