$(function() {   
	var theWindow        = $(window),
		$bg              = $("#bg"),
		aspectRatio      = $bg.width() / $bg.height();
			    			    		
		function resizeBg() {
				
		if ( (theWindow.width() / theWindow.height()) < aspectRatio ) {
			$bg.removeClass().addClass('bgheight');
		}
		else {
			$bg.removeClass().addClass('bgwidth');
		}
	}
			                   			
	theWindow.resize(function() {
		resizeBg();
	}).trigger("resize");
	
	jQuery('#producers_carousel').jcarousel({
		vertical: true,
		scroll: 5
	});
	
	jQuery('.first-and-second-carousel').jcarousel({
		scroll: 3	
	});
	
	$('#producers .jcarousel-item').each(function(i) {
		var prod_title = jQuery(this).find('a').attr('title');
		
		jQuery(this).css('position','relative');
		jQuery(this).append('<div style="z-index: 20000; position: absolute; width: 210px; height: 24px; background-image:url(\'' + global_dir + '/images/fasa_paragwgoi.png\'); background-repeat:no-repeat; top: 110px; color:#0054a6; font-size:13px; text-align:center"><div style="height:4px;"></div>' + prod_title + '</div>');		
	});
	
	var col_heights = parseInt(jQuery('.content').height()) - parseInt(jQuery('.header').height());
	
	var col_left = parseInt(jQuery('.col_1').height());
	var col_middle = parseInt(jQuery('.col_2').height());
	var col_right = parseInt(jQuery('.col_3').height());
	
	var maxValue = Math.max(col_left,col_middle,col_right);

	setTimeout("jQuery('#bg').css('height',jQuery('.content').height() + 'px');",1500);
	
	$('.producer .img span').bind({
		click: function() {
			var prod_name = jQuery(this).parent().parent().find('div.info div.info_name').html();
			var prod_image = jQuery(this).parent().parent().find('div.info div.info_pic').html();
			var prod_desc = jQuery(this).parent().parent().find('div.info div.info_text').html();
			
			jQuery('.producers_text #producer_name').html(prod_name);
			jQuery('.producers_text #producer_image').html(prod_image);
			jQuery('.producers_text #producer_text').html(prod_desc);
		}
	});
	
	$('.gallery_selected li img').bind({
		click: function() {
			jQuery('.gallery_photo img').attr('src',jQuery(this).attr('name'));
		}
	});
	
	$('.days_selected').bind('click', function() {
		
		var arr = $('.days_selected');
		
		arr.each(function(index, item) {
			var original_image = jQuery(this).attr('alt').replace('_over','');
			jQuery(this).attr('src',original_image);
		});
		
		jQuery(this).attr('src',jQuery(this).attr('alt'));
		
		var selected_timetable = jQuery(this).attr('id') + '_time';

		jQuery('.selected_date').html(jQuery('#' + selected_timetable).html());
	});
});

jQuery(window).load(function(){
    jQuery("#nivoslider-577").nivoSlider({
        effect:"random",
        slices:15,
        boxCols:8,
        boxRows:4,
        animSpeed:200,
        pauseTime:3000,
        startSlide:0,
        directionNav:true,
        directionNavHide:true,
        controlNav:true,
        controlNavThumbs:true,
        controlNavThumbsFromRel:true,
        keyboardNav:true,
        pauseOnHover:true,
        manualAdvance:false
    });
    
    $('.nivo-controlNav').appendTo('.thumbs');
});

function volume(imgID) {
	var arr = $('.volume img');
	
	arr.each(function(index, item) {
		if (parseInt(jQuery(this).attr('id')) > imgID)
		{
			jQuery(this).attr('src',global_dir + '/images/volume_down.png');
		}
		else
		{
			jQuery(this).attr('src',global_dir + '/images/volume_up.png');
		}
		
		setVolume(parseInt(imgID) * 10);
	});		
}

function send_email() {
	var email = $("#email").val();
	var name = $("#name").val();	
	var message = $("#message").val();	
	var e = $(".main").attr('id');	
				
	if ( (email=='') || (name=='') || (message=='') )
	{
		alert('Παρακαλούμε συμπληρώστε όλα τα στοιχεία.');
	}
	else
	{
		jQuery.ajax({
			type: "POST",
			url: global_dir + "/modules/send_prod.php",
			data: "email=" + email + "&name=" + name + "&message=" + message + "&e=" + e,
			success: function(msg){
				alert('Το μήνυμά σας στάλθηκε επιτυχώς στον παραγωγό.');
			}
		});
	}
}

function reset_contact() {
	$("#cname").val('First name');
	$("#clastname").val('Last name');
	$("#cemail").val('E-mail');
	$("#csubject").val('Subject');
	$("#creason").val('Reason of mailing');
	$("#creceiver").val('Receiver');
	$("#cmessage").val('Type in here');
}

function send_contact() {
	var cname = $("#cname").val();
	var clastname = $("#clastname").val();
	var cemail = $("#cemail").val();
	var csubject = $("#csubject").val();
	var creason = $("#creason").val();
	var creceiver = $("#creceiver").val();
	var cmessage = $("#cmessage").val();
	
	if (cname == 'First name')
	{
		cname = '';	
	}
	
	if (clastname == 'Last name')
	{
		clastname = '';	
	}
	
	if (cemail == 'E-mail')
	{
		cemail = '';	
	}
	
	if (csubject == 'Subject')
	{
		csubject = '';	
	}
	
	if (creason == 'Reason of mailing')
	{
		creason = '';	
	}
	
	if (creceiver == 'Receiver')
	{
		creceiver = '';	
	}
	
	if (cmessage == 'Type in here')
	{
		cmessage = '';	
	}
	
	if ( (cname == '') || (clastname=='') || (cemail=='') || (csubject=='') || (creason=='') || (creceiver=='') || (cmessage == '') )
	{
		jQuery('#contact_answer').html('<img src="' + global_dir + '/images/contact_not_ok.png" />');	
	}
	else
	{
		jQuery.ajax({
			type: "POST",
			url: global_dir + "/modules/send_contact.php",
			data: "cname=" + cname + "&clastname=" + clastname + "&csubject=" + csubject + "&creason=" + creason + "&creceiver=" + creceiver + "&cmessage=" + cmessage + "&cemail=" + cemail,
			success: function(msg){
				jQuery('#contact_answer').html('<img src="' + global_dir + '/images/contact_ok.png" />');
			}
		});
	}
}

