$(function(){
	
    /** IE/ überhekk annak aki nem bírja kidobni ezt a @&#{Ł$ **/
    
    if($.browser.msie && parseInt($.browser.version) == 6) {
        $("#header #main_menu").width($(window).width());
        $("#footer").css("top", $(window).height() - 22);   
    }
    	   
	var mxHeight = 0;	
	$(".columns").each(function() {
		if($(this).height() > mxHeight) {
			mxHeight = $(this).height();
		}
	}).height(mxHeight);
    
	$(".csbody").toggle(function(/*e*/) {
		//if(e.target.tagName != "A" && e.target.tagName != "LI" && e.target.className != "cstext") {
			$(this).children("ul").show();
		//}
	}, function(/*e*/) {
        //if(e.target.tagName == "A" && e.target.tagName != "LI" && e.target.className != "cstext") {                              
            $(this).children("ul").hide();
        //}
    });
	
	$(".csbody ul li").not(".head").click(function() {
		$(this).parents(".csbody").children(".cstext").text($(this).text());
        var val = $(this).children().attr("rel");
        $(this).parents(".csbody").children(".csval").text(val);
		$(this).parents(".csbody ul").hide();
        
        //selected item change
        $(this).trigger("csChange", [val]);
	}).hover(function() {
		$(this).css("background-color", "#003399").children("a").css("color", "#FFF");	
	}, function() {
		$(this).css("background-color", "#FFF").children("a").css("color", "#4C4C4C");	
	});
    
    $(".customselect .input[name=search], .customselect .input[name=mp_search]").click(function() {
        if($(this).val() == "Keresés...") {
            $(this).val("");
        }
    }).blur(function() {
        if($(this).val() == "") {
            $(this).val("Keresés...");
        }
    });
	
	
	/* Navigation menu control */
	$("#navigation_footer").click(function() {								   
		$("#navigation_list").slideUp(function() {
			$("#navigation_top").show();
            $("#navigation_header").css("border-bottom", "1px solid #7B7B7B");										   
		});					 
	}).hover(function() {
		$(this).css("background-position", "0px -12px");	
	}, function() {
		$(this).css("background-position", "0px 0px");	
	});
	
	$("#navigation_top").click(function() { 							
		$(this).hide();
		$("#navigation_header").css("border-bottom", "none");
		$("#navigation_list").slideDown();
	}).hover(function() {
		$(this).css("background-position", "0px -12px");	
	}, function() {
		$(this).css("background-position", "0px 0px");	
	});
	
	/* Topmenu control */
	var menuHoverable = false;
	var layerOpen = false;
	$(".mainmenu > .menuitem > a").not("#home, #config").click(function() {
		var li_a = $(this);
		li_a.next(".layer").show(1, function() {							  
			li_a.removeClass().addClass("openlayer");
			layerOpen = true;
			menuHoverable = true;
            $("#navigation_top").css("z-index", "1");
			$("#navigation_list").css("z-index", "9");
		});
		
	}).mouseover(function() {
		if(menuHoverable) {
			clearAll();
			var li_a = $(this);
			li_a.next(".layer").show(1, function() {							  
				li_a.removeClass().addClass("openlayer");
				layerOpen = true;
				$("#navigation_top").css("z-index", "1");
                $("#navigation_list").css("z-index", "9");
			});	
		}
	});
	
	function clearAll() {
		$("#navigation_top").css("z-index", "12");
        $("#navigation_list").css("z-index", "11");
		$(".mainmenu > .menuitem > a").not("#home, #config").each(function() {
			var li_a = $(this);
			li_a.next(".layer").hide(1, function() {							  
				li_a.removeClass("openlayer");	
				layerOpen = false;
			});
		});
	}
	
	$(document).click(function() {
        $(".csbody ul").hide();
		if(layerOpen) {
			clearAll();	
		}
		menuHoverable = false;
    });
    
    /* Content Column height fixes */
    /*var column1Height = $("#content .text_column1").offset().top + $("#content .text_column1").height();
    var column2Height = $("#content .text_column2").height(); 
    var column3Height = $("#content .text_column3").height(); 
    if(column1Height > column2Height && column1Height > column3Height) {
        $("#content .text_column3").height(column1Height - 120);
    }
    if(column2Height > column1Height && column2Height > column3Height) {
        $("#content .text_column3").height(column2Height - 120);
    }*/
    
    $(".c_possibilities img").not(".lens").hover(function() {
        var idx = $(".c_possibilities img").not(".lens").index($(this));
        $("img.lens").eq(idx).attr("src", baseUrl + "images/lens-h.gif");    
    }, function() {
        var idx = $(".c_possibilities img").not(".lens").index($(this));
        $("img.lens").eq(idx).attr("src", baseUrl + "images/lens.gif");
    });
    
    $(".faqdiv").hide().eq(0).show();
    $("a[rel=content_opener]").each(function(i, item) {
        if(i == 0 && $(".ddiv[rel=active]").length == 0) {
            $(this).removeClass().addClass("xrelated_link_active");    
        }
        $(this).click(function() {
            $("a[rel=content_opener]").removeClass().addClass("xrelated_link");
            $(this).removeClass().addClass("xrelated_link_active");
            $(".faqdiv").hide().eq(i).show();
        });    
    });
    
    if($(".ddiv[rel=active]").length == 0) {
        $(".ddiv").hide().eq(0).show();
    } else {
         $(".ddiv").hide();
         $(".ddiv[rel=active]").show();
    }
    $(".dfile").hide().eq(0).show();
    $("a[rel=content_opener]").each(function(i, item) {
        if(i == 0 && $(".ddiv[rel=active]").length == 0) {
            $(this).removeClass().addClass("xrelated_link_active");    
        }
        $(this).click(function() {
            $("a[rel=content_opener]").removeClass().addClass("xrelated_link");
            $(this).removeClass().addClass("xrelated_link_active");
            $(".ddiv").hide().eq(i).show();
            $(".dfile").hide().eq(i).show();
            $(".cscroll#news_content").show();
            $("#text_wrap").css("top", 0);
            $(".scrollbody_news_content").css("top", 0);
            //dragHandle(".scrollbody_news_content", 358, "#text_wrap", ".text_column2", 450, ".cscroll#news_content a", ".cscroll#news_content");
        });    
    });

});


function preview(img) {
    $("#big_image_layer").html('<img width="510" border="0" src="'+img+'" /><br /><br /><a class="xrelated_link" href="javascript:previewClose()">Bezárás</a><br /><br />').show();
}

function previewClose() {
    $("#big_image_layer").hide();
}

function fillData(type, column) {
    $.getJSON("index.php",
        { type : type, cmd : "gettechnicaldata" },
        function(data) {
            $(data).each(function(i, item) {
                if(item.key == "") {
                    //alapár
                    $("table.data tr:last td:eq(" + column + ")").text(item.val);     
                } else if(item.key == "color") {
                    //kép
                    $("#md_image" + column).attr("src", item.val);                    
                } else {
                    $("table.data tr td:contains('" + item.key + "')").parent().children(":eq(" + column + ")").text(item.val);                
                }
            });
        }
    );
}

function printDataSheet() {
    window.print();    
}     