var J = jQuery.noConflict();
function toggleClass(element, className){
    (element.hasClass(className)) ? (element.removeClass(className)) : (element.addClass(className))
}
J(window).load(function (){
/* Toggle city */
J('#toggle_cities').click(function() {
    if(J(this).hasClass('hide_cities')){
         J('#header_city').animate({height: '30px'}, 500)
    } else{
         J('#header_city').animate({ height: '100%'}, 1000)
    }
    toggleClass(J(this), 'hide_cities')
})

/* Contact tab */
    J('#sea_port_contact_info').hide();
    J("#contact_odessa").click(function(){
        if(!J(this). hasClass('active')){
            toggleClass(J(this), 'active')
            toggleClass(J("#contact_sea_port"), 'active')
            J("#sea_port_contact_info").hide();
            J("#odessa_contact_info").show();
        }
    })
    J("#contact_sea_port").click(function(){
        if(!J(this). hasClass('active')){
            toggleClass(J('#contact_odessa'), 'active')
            toggleClass(J(this), 'active')
            J("#odessa_contact_info").hide();
            J("#sea_port_contact_info").show();
        }
    })

/* SUBMITE ORDER */
    J('#result_order').change(function(){
        J('#result_order  option:selected').each(function () {
            set = J(this).attr('value')
        })
        J('#order_dir').attr('value', set)
        J('#cruise_form_search').submit();
    })
/* Tabs on mane page */
    J('input.plan_submit').hover(
        function() { J(this).addClass('plan_submit_hover'); },
        function() { J(this).removeClass('plan_submit_hover');
    });
	J('input.contact_submit').hover(
        function() { J(this).addClass('contact_submit_hover');},
		function() {J(this).removeClass('contact_submit_hover');
    });
	J("div#p_content_tour").hide();
	J("div#p_tour").click(function(){
		J(this).addClass("active_t");
		J("div#p_cruise").removeClass("active_c");
		J("#p_content_tour").show();
		J("#p_content").hide();
    })
	J("div#p_cruise").click(function(){
		J(this).addClass("active_c");
		J("div#p_tour").removeClass("active_t");
		J("#p_content_tour").hide();
		J("#p_content").show();
    })

/* hide all sub tables */
    J('.pull_down_tr').each(function(){ J(this).hide() })

	J(".excursion").click(function(){
        main_tr = J(this).parents('tr')
        main_tr.children().each(function(){
            toggleClass(J(this), 'shedule_pull_down')
            if(J(this).hasClass('excursion')){ toggleClass(J(this), 'excursion_image') }
        })
        main_tr.next().toggle()
    })
    J(".cruise_details_row").click(function(){
        main_tr = J(this)
        main_tr.children().each(function(){
            toggleClass(J(this), 'date_pull_down')
            if(J(this).hasClass('arrows')){ toggleClass(J(this), 'date_pull_down_img') }
        })
        main_tr.next().toggle()
    })
/* Toggle tables */
    J("th.hide").click(function(){
    (J(this).hasClass('show')) ? J(this).removeClass('show') : J(this).addClass('show')
    J(this).parents('thead').next().toggle()
	})

/* search */
    /* hide wide fieldss */
    J('.wide_search').each(function(){ J(this).hide() })
    J("#search_adv").click(function(){
        J('.wide_search').each(function(){ 
            J(this).toggle()
            toggleClass(J('.finding'), 'finding_arrow')
        })
    })

/* row hightlite*/
	J('.cruise_shedule_row').hover(
		function(){J(this).addClass('cruise_shedule_hover')},
		function() {J(this).removeClass('cruise_shedule_hover');
	});
	J('.cruise_details_row').hover(
		function(){J(this).addClass('cruise_date_hover')},
		function() {J(this).removeClass('cruise_date_hover');
	});
	J('.cruise_details_row').hover(
		function(){J(this).addClass('cruise_hotel_hover')},
		function() {J(this).removeClass('cruise_hotel_hover');
	});

/* buttons*/
	J('input.plan_submit').hover(
		function(){J(this).addClass('plan_submit_hover');},
		function() {J(this).removeClass('plan_submit_hover');
	});

	J('input.contact_submit').hover(function()
		{J(this).addClass('contact_submit_hover');},
		function() {J(this).removeClass('contact_submit_hover');
	});

	J('input.opinion_submit').hover(function(){
		J(this).addClass('opinion_submit_hover');
		},
		function() {
		J(this).removeClass('opinion_submit_hover');
		});

	J('input.find_submit').hover(function(){
		J(this).addClass('find_submit_hover');
		},
		function() {
		J(this).removeClass('find_submit_hover');
		});
	J('input.contact_submit_layout').hover(function(){
		J(this).addClass('contact_submit_layout_hover');
		},
		function() {
		J(this).removeClass('contact_submit_layout_hover');
		});

/* Doc list */
	J('.doc_item').hover(
		function(){J(this).addClass('active_doc');},
		function() {J(this).removeClass('active_doc');
	});
	J('.pdf_item').hover(
		function(){J(this).addClass('pdf_item_gray');},
		function() {J(this).removeClass('pdf_item_gray');
	});
/* Team */
    click_count = 0;
	J(".user_info").click(function(){		
    	J(this).next().css({display:"block"});  
    	
        if (J(this).hasClass('hide_derection')) {
        	J(this).next().css({display:"none"});
        } else {
        	J(this).next().css({display:"block"});
        }
        
        toggleClass(J(this), 'hide_derection');
	})

/* Tour page */
	J('.tour_info').hover(
		function(){J(this).addClass('about_tour_hover');},
		function() {J(this).removeClass('about_tour_hover');
	});
	J('.tour_info').click(function(){
        J(this).next().toggle();
        J(this).children().each(function(){
            if(J(this).hasClass('arrows')){ toggleClass(J(this), 'about_tour_down_img') }
            if(J(this).hasClass('pricing')){
                J(this).children().each(function(){ if(J(this).hasClass('for_hide')){ toggleClass(J(this), 'hide_element') } })
            }
        })
    })

/* regions/country/city script */
    region_id = 'regions_tour'
    country_id = 'countries_tour'
    cities_id = 'cities_tour'

	var region_select = J('#' + region_id).html();
	var country_select = J('#' + country_id).html();
	var cities_select = J('#' + cities_id).html();

	function showAllRegion(){ J('#' + region_id).html(region_select);}
	function showAllCountries(){ J('#' + country_id).html(country_select);}
	function showAllCities(){ J('#' + cities_id).html(cities_select);}
	
	J('#' + region_id).change(function(event) {
		element = Event.element(event);
		value = element.getValue();
			if (value == '') {
				value='all';
				J('#selectcities_tour').html('<img src="/images/loader.gif" width="15">');
				J.ajax({url: '/ajax_city_select/'+value+'/', success: function(msg){
					J('#' + cities_id).html(msg);
					J('#selectcities_tour').html('Выберите город');
				   }
				});			
			}
			J('#selectcountries_tour').html('<img src="/images/loader.gif" width="15">');
			J.ajax({url: '/ajax_country_select/'+value+'/', success: function(msg){
				J('#' + country_id).html(msg);
				J('#selectcountries_tour').html('Выберите страну');
			   }
			});
	})
	
	J('#' + country_id).change(function(event) {
		element = Event.element(event);
		value = element.getValue();
		if (value == '') {value='all';}
			J('#selectcities_tour').html('<img src="/images/loader.gif" width="15">');
			J.ajax({url: '/ajax_city_select/'+value+'/', success: function(msg){
				J('#' + cities_id).html(msg);
				J('#selectcities_tour').html('Выберите город');
			   }
			});
	})
});

jQuery(document).ready(function() {
    J('#gallery').jcarousel({
        buttonNextHTML: J('#next_button'),
        buttonPrevHTML: J('#prev_button'),
        scroll: 1
    });
    J('#gallery_liner').jcarousel({
        buttonNextHTML: J('#next_button'),
        buttonPrevHTML: J('#prev_button'),
        scroll: 1
    });
    J(".jcarousel-item a").fancybox({
    });

});
/* Cruise */
jQuery(document).ready(function() {
    J('#gallery_cruise').jcarousel({
        buttonNextHTML: J('#imgs_arrow_right'),
        buttonPrevHTML: J('#imgs_arrow_left'),
        scroll: 1
    });
});


function setActiveCabin(id){
    if(id + '' != 'undefined'){
        J("#cabin_category li").each(function(){
            J(this).removeClass('cabin_tr_hover')
            class_name = J(this).children("div")[0]
            link_name = J(this).children("div")[1]
            J(class_name).removeClass('cabin_class_hover')
            J(J(link_name).children('a')[0]).removeClass('cabin_name_hover')
        })
        J("#cabin_category #cabin_" + id).each(function(){
            J(this).addClass('cabin_tr_hover')
            class_name = J(this).children("div")[0]
            link_name = J(this).children("div")[1]
            J(class_name).addClass('cabin_class_hover')
            J(J(link_name).children('a')[0]).addClass('cabin_name_hover')
        })
    }
}

function setActiveDeck(id){
    if(id + '' != 'undefined'){
        J("#deck_name li").each(function(){
            J(this).removeClass('deck_name_hover')
            link = J(this).children("a")[0]
            J(link).children().each(function(){ J(this).removeClass('deck_name_active') })
        })
        J("#deck_name #deck_" +id).each(function(){
            J(this).addClass('deck_name_hover')
            link = J(this).children("a")[0]
            inner_div = J(link).children()
            J(inner_div[2]).addClass('deck_name_active')
        })
    }
}

function hideDeckInfo(){
    J('#deck_data_content_one').children().each(function(){
        J(this).animate({ opacity: 0.2}, 2000)}
       );
    J('#deck_data_content_two #cabin_desc').animate({ opacity: 0.2}, 2000)
    J('#deck_data_content_two #cabin_category').animate({ opacity: 0.2}, 2000)
}
function showDeckInfo(){
    J('#deck_data_content_one').children().each(function(){
        J(this).animate({ opacity: 1}, 1000)}
       );
    J('#deck_data_content_two #cabin_category').animate({ opacity: 1.0}, 2000)
    J('#deck_data_content_two #cabin_desc').animate({ opacity: 1.0}, 2000)
}
