$(document).ready(function(){

	$('#huzat_id').change(function(){
		$("#product-right-item button").removeAttr("disabled"); 
	    $('.szolg').hide();
	    $('#' + $(this).val()).show();
	    var mainId = $(this).val();
		if (mainId!=""){
	    var mainImage = $("#"+mainId+" .colors-item a").attr("href");
	    var mainTitle = $("#"+mainId+" .colors-item img").attr("alt");
	    var mainColorId = $("#"+mainId+" .colors-item img").attr("title");
	    $("#imgcontainer img").attr({ src: mainImage });
	    $("#titleplace").html('&nbsp;&nbsp;-&nbsp;&nbsp;' + mainTitle);
	    $("#color_id").attr("value", mainColorId);
	    price();}else{
			
			$("#product-right-item button").attr("disabled", "disabled");
			
		}
	});
	
	//Színcserélés
	$(".colors-item a").click(function() {
		
		var mainImage = $(this).attr("href");
		var mainTitle = $("img", this).attr("alt");
		var mainColorId = $("img", this).attr("title");
		$("#imgcontainer img").attr({ src: mainImage });
		$("#titleplace").html('&nbsp;&nbsp;-&nbsp;&nbsp;' + mainTitle);
		$("#color_id").attr("value", mainColorId); 
		return false;		
	});
	
	//ToolTIP
	$('.colors-item').tooltipsy({
	css: {
        'padding': '5px',
        'max-width': '200px',
        'color': '#303030',
        'background-color': '#f5f5b5',
        'border': '1px solid #deca7e',
        '-moz-box-shadow': '0 0 10px rgba(0, 0, 0, .5)',
        '-webkit-box-shadow': '0 0 10px rgba(0, 0, 0, .5)',
        'box-shadow': '0 0 10px rgba(0, 0, 0, .5)',
        'text-shadow': 'none'
    }

	});
	
	if ($("input[name='szalmod']:checked").val() == '1'){
		$("#szamlazasi_adatok").css("display","block");
		$("#szallitasi_adatok").css("display","none");     
	}else if ($("input[name='szalmod']:checked").val() == '2'){
		$("#szamlazasi_adatok").css("display","block");
		$("#szallitasi_adatok").css("display","block");
	}
	
	$("input[name='szalmod']").change(function(){
	    if ($("input[name='szalmod']:checked").val() == '1'){
	     
	       $("#szamlazasi_adatok").css("display","block");
	       $("#szallitasi_adatok").css("display","none");
	       
	    }else if ($("input[name='szalmod']:checked").val() == '2'){
	    	$("#szamlazasi_adatok").css("display","block");
	       	$("#szallitasi_adatok").css("display","block");
	    }else if ($("input[name='szalmod']:checked").val() == '3'){
	    	$("#szamlazasi_adatok").css("display","block");
	       	$("#szallitasi_adatok").css("display","block");
	    }
	});
	
	
	//Checkbox
	$('#copyszamadat').bind('change', function () {
	
	   if ($(this).is(':checked')){
	   
	   		var sz_name = $('#sz_name').val();
	   		var	sz_orszag = $('#sz_orszag').val();
	   		var	sz_varos = $('#sz_varos').val();
	   		var	sz_cim = $('#sz_cim').val();
	   		var	sz_irsz = $('#sz_irsz').val();
	   		
	   		$('#sza_name').val(sz_name);
	   		$('#sza_orszag').val(sz_orszag);
	   		$('#sza_cim').val(sz_cim);
	   		$('#sza_varos').val(sz_varos);
	   		$('#sza_irsz').val(sz_irsz);
	   
	   }  
	
	});
	
	// if user clicked on button, the overlay layer or the dialogbox, close the dialog	
	$('a.btn-ok, #dialog-overlay, #dialog-box').click(function () {		
		$('#dialog-overlay, #dialog-box').hide();		
		return false;
	});
	
	// if user resize the window, call the same function again
	// to make sure the overlay fills the screen and dialogbox aligned to center	
	$(window).resize(function () {
		
		//only do it if the dialog box is not hidden
		if (!$('#dialog-box').is(':hidden')) popup();		
	});
	
	

});

//Ár kiíratása
function price(katID){
	
	var csh = $('#huzat_id').val();
	
	if(csh!="" & csh!="-" & csh!="0"){
		$("#product-right-item button").removeAttr("disabled");
	}
	
	var kat = $("select[name='huzat_id']").attr("selected", true);
	var katI = kat.val();
	var katId = katI.substring(1, katI.length)
	var radiobtn = $('input[name=huzat]:checked').val();
	var pric = $("#"+katId+"_"+radiobtn+"").val();
	var pric_a = $("#"+katId+"_"+radiobtn+"_a").val();
	
	if(pric == 0){
		$("#product-right-item button").attr("disabled", "disabled");
		$("#priceplace").html("-");
	} else{   

		if (pric_a!=0){
		
			$("#priceplace").html(pric);
			$("#priceplace_akcios").html(pric_a);
			$("#price_akcios").css("display", "block");
			$("#priceplace").css({'text-decoration': 'line-through', 'font-size': '19px'});
			
		} else {
			$("#priceplace").html(pric);
			$("#price_akcios").css("display", "none");
			$("#priceplace").css({'text-decoration': 'none'});
		
		}

    }
}

//Popup dialog
function popup(message) {
		
	// get the screen height and width  
	var maskHeight = $(document).height();  
	var maskWidth = $(window).width();
	
	// calculate the values for center alignment
	var dialogTop =  (maskHeight/3) - ($('#dialog-box').height());  
	var dialogLeft = (maskWidth/2) - ($('#dialog-box').width()/2); 
	
	// assign values to the overlay and dialog box
	$('#dialog-overlay').css({height:maskHeight, width:maskWidth}).show();
	$('#dialog-box').css({top:dialogTop, left:dialogLeft}).show();
	
	// display the message
	$('#dialog-message').html(message);
			
}

//Scroll to Top
$(function() {
	$(window).scroll(function() {
		if($(this).scrollTop() != 0) {
			$('#toTop').fadeIn();	
		} else {
			$('#toTop').fadeOut();
		}
	});
 
	$('#toTop').click(function() {
		$('body,html').animate({scrollTop:0},800);
	});	
});

$(function(){
    $('a.new-window').click(function(){
        window.open(this.href);
        return false;
    });
});
