/**
 * @author Alexander Farkas
 * v. 1.02
 */
(function($) {
	$.extend($.fx.step,{
	    backgroundPosition: function(fx) {
            if (fx.state === 0 && typeof fx.end == 'string') {
                var start = $.curCSS(fx.elem,'backgroundPosition');
                start = toArray(start);
                fx.start = [start[0],start[2]];
                var end = toArray(fx.end);
                fx.end = [end[0],end[2]];
                fx.unit = [end[1],end[3]];
			}
            var nowPosX = [];
            nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
            nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
            fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

           function toArray(strg){
               strg = strg.replace(/left|top/g,'0px');
               strg = strg.replace(/right|bottom/g,'100%');
               strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
               var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
               return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
           }
        }
	});
})(jQuery);


jQuery(function() {

///// animated nav
jQuery("#a li:not('.current_page_item'), #a li:not('.current_page_item')")
	.css( {backgroundPosition: "left 40px"} )
	.mouseover(function(){
		jQuery(this).stop().animate({backgroundPosition:"(left -17px)"}, {duration:500})
		//$('a',this).css({'color':'#fff'});
	})
	.mouseout(function(){
		jQuery(this).stop().animate({backgroundPosition:"(left 40px)"}, {duration:200, complete:function(){
			jQuery(this).css({backgroundPosition: "-20px 35px"})
		}})
	})

jQuery("#b li:not('.hotel_list_sel')")
	.css( {backgroundPosition: "left 40px"} )
	.mouseover(function(){
		jQuery(this).stop().animate({backgroundPosition:"(left -17px)"}, {duration:200})
		//$('a',this).css({'color':'#fff'});
	})
	.mouseout(function(){
		jQuery(this).stop().animate({backgroundPosition:"(left 40px)"}, {duration:200, complete:function(){
			jQuery(this).css({backgroundPosition: "left 45px"})
		}})
	})

// homepage
$('#pics').cycle({
        speed:  3000,
        timeout: 2000,
        pager:  '#specials_wrap',
        pagerAnchorBuilder: function(idx, slide) {
            // return sel string for existing anchor
            return '#specials_wrap li:eq(' + (idx) + ') ';
        }
    });

//homepage clicks
$('#specials_wrap div').click(function(){
	$('.himg').attr('href',$(this).attr('id'));
})



///////////////////////

$('#home_flash_wrap').onImagesLoad({ 
            selectorCallback: selectorImagesLoaded 
}); 


function selectorImagesLoaded($selector){ 
		//slideshow
// new homepage
$('#flash-pics').cycle({
        speed:  3000,
        timeout: 2000,
        pager:  '#home_flash',
        pagerAnchorBuilder: function(idx, slide) {
            // return sel string for existing anchor
           // return '#home_flash li a:eq(' + (idx) + ') ';
        }
    });


        } 




/////////// new homepage
//homepage clicks
$('#specials_wrap div').click(function(){
	$('.himg').attr('href',$(this).attr('id'));
})




// price page td color
$(".tbl_lgray tr:even").css("background-color", "#ddd");
$(".tbl_dgray tr:even").css("background-color", "#ddd");
//$(".tbl_dgray tr:even").css("color", "#fff");


// kontak date input
$(".date_input").date_input();

//flights page
/*
$('.data_flights td:not(:first-child)').click(function () {
	var mmt = $.trim($(this).text());
	if(mmt != '-' && mmt !== '' && mmt !== '0'){
		$('.data_flights td').removeAttr('id');

		$('#link_to_kontak a').attr('href','kontak/'+$(this).attr('id','hylyt').children("input[@type=radio]").val());
	//	alert($('#link_to_kontak a').attr('href'));
		$(this).attr('id','hylyt').children("input[@type=radio]").click();
}
  })

//hover must be below click event
$('.data_flights td:not(:first-child)').hover(function(){
	var mmt = $.trim($(this).text());
	if(mmt != '-' && mmt !== '' && mmt !== '0'){
	$(this).css('cursor','pointer');
	}
}, 
//mandatory for hover! should have known///
      function () {
       // $(this).find("span:last").remove();
      }
)
*/

//hotel page - image scroller on the top
    
		$("#viewer").imageScroller({
			next:"btn1",
			prev:"btn2",
			frame:"viewerFrame",
			width:100,
			child:"a",
			auto:true
		});
			 
//hotel - gallery
/*    $('#slideshow').cycle({
        fx:     'fade',
        speed:  'fast',
        timeout: 0,
        pager:  '#navs',
        pagerAnchorBuilder: function(idx, slide) {
            // return sel string for existing anchor:not(:first-child)
			            return '#navs li:eq(' + (idx) + ') a';			
        }
    });*/
   
$("#stop img").toggle(
  function () {
	  $(this).attr('src','http://barrom.travel/wp-content/themes/barrom/images/btn_play.jpg');
	  $('#s2').cycle('pause');
  },
  function () {
  	$(this).attr('src','http://barrom.travel/wp-content/themes/barrom/images/btn_stop.jpg');
	$('#s2').cycle('resume');
  }
);


// form validation
$("#kontak").validate({
        rules: 
		{
          name: "required",
		  vorname: "required",
		  telefonnummer: "required",
		  telefonnummer2: "required",
          hotel_ankunft: "required",
		  hotel_abreise: "required",
		  flights_hinflug: "required",
		  flights_ruckflug: "required",		  
          email: {// compound rule
          required: true,
          email: true
        },
        url: 
		{
          url: true
        },
        comment: 
		{
          required: true
        }
        },
        messages: {
		   name: '',
		   vorname: '',
          hotel_ankunft: "",
		  hotel_abreise: "",
		  flights_hinflug: "",
		  flights_ruckflug: "",			   
		   email:'',
          comment: "Please enter a comment.",
		  telefonnummer: '',
		  telefonnummer2: ''
        }
      });


$("#signup").validate({
        rules: 
		{
          attribute1: "required",
          email: {// compound rule
          required: true,
          email: true
        },
        url: 
		{
          url: true
        },
        comment: 
		{
          required: true
        }
        },
        messages: {
		   attribute1: '',
		   email:''
        }
      });


//alert(location.pathname);
// chain select

        $('#land').chainSelect('#desti','http://barrom.travel/chain.php',
        { 
                before:function (target) //before request hide the target combobox and display the loading message
                { 		
                        $("#loading").css("display","block");
                },
                after:function (target) //after request show the target combobox and hide the loading message
                { 
                        $("#loading").css("display","none");
                }

        });

        $('#desti').chainSelect('#hhotel','http://barrom.travel/chain.php',
        { 
                before:function (target) 
                { 
                        $("#loading").css("display","block");
                },
                after:function (target) 
                { 
                        $("#loading").css("display","none");
                }
        });

        $('#land2').chainSelect('#desti2','http://barrom.travel/chain2.php',
        { 
                before:function (target) //before request hide the target combobox and display the loading message
                { 		
                        $("#loading").css("display","block");
                },
                after:function (target) //after request show the target combobox and hide the loading message
                { 
                        $("#loading").css("display","none");
                }

        });


        $('#desti2').chainSelect('#hhotel','http://barrom.travel/chain2.php',
        { 
                before:function (target) 
                { 
                        $("#loading").css("display","block");
                },
                after:function (target) 
                { 
                        $("#loading").css("display","none");
                }
        });


//////////// hotel maps
	//ACCORDION BUTTON ACTION	
	$('div.accordionButton').click(function() {
		
		$('div.accordionButton').removeClass('selected_h3');											
		if($(this).next().is(':visible')) {
			$(this).removeClass('selected_h3');			
			$('div.accordionContent').slideUp('normal');
			
		} else {
			$(this).addClass('selected_h3');
			$('div.accordionContent').slideUp('normal');	
			$(this).next().slideDown('normal');
		}

	});
 
	//HIDE THE DIVS ON PAGE LOAD	
//	$("div.accordionContent").hide();

////////// tooltip
 $(".abs").tooltip({  position: 'center right', effect: 'slide'	, delay : 300, offset :[0, -15] });  
/*     $(".abs").mouseover(function(){
		$(".abs").addClass("border");
								  
    }).mouseout(function(){
		$(".abs").addClass("border");

    });*/

$(".abs img").each(function () {
	// get parent div							   
	$(this).css('width',$(this).parent().width());		
//	alert($(this).parent().width());
	$(this).css('height',$(this).parent().height());
	//alert($(this).parent().attr('id') + ' - ' + $(this).css('height'));
});


$("#mailform").validate({
        rules: 
		{
          myname: "required",
          mymail: {// compound rule
         			 required: true,
          			email: true
        			},		  
          fmail: {// compound rule
          			required: true,
		 			 email: true
        			},
		
		  fname: "required"
        },
        messages: {
		   myname: '',
		   mymail: '',
          fname: "",
		  fmail: "",
		  comment: ""		  
        }
      });


	$("a#maillink").click(function(event) {
	  event.preventDefault();
	   $("#mail_me").slideToggle("slow");
	  
	});
		
});

