//Activate Immediately
jQuery(function() {

    $(".delme").focus(function(){
        if ($(this).is('input')) {
            var orival = $(this).val();
            $(this).val("");
        }else{
            var orival = $(this).html();
            $(this).html("");
        }

        $(this).blur(function(){
            if($(this).is('input')){
                if ($(this).val() != "" && $(this).val() != orival) {
                    $(this).removeClass('delme').unbind('blur').unbind('focus');
                }else{
                    $(this).val(orival);
                }
            }else{
                if ($(this).html() != "" && $(this).html() != orival) {
                    $(this).removeClass('delme').unbind('blur').unbind('focus');
                }else if ($.browser.safari && $(this).val() != "" && $(this).val() != orival) {
                    $(this).removeClass('delme').unbind('blur').unbind('focus');
                }else{
                    $(this).html(orival);
                }
            }

        });
    });
	    /*
     * Begin Ticker
     */	
		$(".ticker").jCarouselLite({
		vertical:true,									 
        visible: 1,  
        auto:4000,  
        speed:2000,
		scroll:1,
		easing:'swing'
    });	
    /*
     * Begin form Validate
     */	
			$("#commentform").validate({		
			//set the rules for the field names
			rules: {
				name: {
					required: true,
					minlength: 2
				},
				email: {
					required: true,
					email: true
				},							
				comment: {
					required: true,
					minlength: 2
				}
			},	
			//set messages to appear inline
			messages: {
				name: {
					required:"Enter your Name",
					minlength:"Enter atleast 2 characters"
				},
				email: {
					required:"An email is required",
					email:"Enter a valid e-mail"
				},
				comment: {
					required:"A message is required",
					minlength:"Enter atleast 5 characters"
				}
			},
			
			//hide errors forever. We just need element highlighting
			errorPlacement: function(error, element) {
				error.hide();
			},

			//Submit the Form  
			submitHandler: function() {			
			//Post the form values via ajax post 
				$.post($("#commentform").attr('action'), $("#commentform").serialize()+'&ajax=1', function(result){				
						$('#commentform').remove();		//hide comment form
						$('#mail_success').fadeIn(500);	//Show mail success div			
				});			
			}		
		});
     /*
     * Begin infinite slider by reset
     */
    jQuery.fn.infinteSlider = function(options){
        //alert(this.tagName);
        //        this.each(function(){
        //            alert(this.tagName);
        //        });
        
        /*
         *Init zone
         */
        var settings = {
            focusFrame : false,
            infiniteMode : false,
            naviMarkup : '<div class="slider-navi"><a class="foward"></a><a class="back"></a></div>'
        };
        jQuery.extend(settings, options);
        var naviMarkup = settings.naviMarkup;
        var cont = this;
        var navi;
        /*
         * Find out what is the sliding content, the container and the buttons
         */
        if(cont.find('ul').html()){
            var elCont = cont.find('ul');
            var elem = elCont.children();
            if(!cont.find('.back')){
                elCont.after(naviMarkup);
            }
        }else{
            var elem = cont.children();
            var elCont = cont;
            if(!elCont.parent().find('.back')){
                elCont.after(naviMarkup);
            }
        }
        var navi = cont.find(".back").parent();
        var cont = this;
        var startLeft = 0;
        var init = function(){
            
            if(settings.focusFrame){
                startLeft = jQuery(settings.focusFrame).offset().left;
            }
            if(elCont.css('left') == "auto"){
                elCont.css('left', 0);
            }
            elCont.css({
                left : parseInt(elCont.css('left'))+startLeft
            });
            elCont.width(elem.width()*elem.length);
            slideBind();
            if(settings.infiniteMode){
                fillBefore();
            }
            
        };
        var fillBefore = function(num){
            startLeft = parseInt(elCont.css('left'))-(elem.length*elem.width());
            elCont.prepend(elCont.html()).width(elem.width()*elCont.children().length).css("left", startLeft);
            elem = elCont.children();
        };
        var slideFoward = function(){
            if(settings.infiniteMode){
                elCont.children(":first").appendTo(elCont);
                elCont.css({
                    left : parseInt(elCont.css('left'))+elCont.find(":first").width()
                });
            }
            var newLeft = parseInt(elCont.css('left'))-elCont.find(":first").width()-(parseInt(elCont.find(":first").css("marginRight"))+parseInt(elCont.find(":first").css("marginLeft")));
            //alert(newLeft);
            elCont.animate({
                left : newLeft
            }, 600, function(){
                //alert(elCont);
                slideBind();
            });
        };
        var slideBack = function(){
            if(settings.infiniteMode){
                elCont.children(":last").prependTo(elCont);
                //alert(1);
                elCont.css({
                    left : parseInt(elCont.css('left')) - elCont.children(":first").width()
                });
            }
            //alert(2);
            var newLeft = parseInt(elCont.css('left'))+elCont.find(":first").width()+(parseInt(elCont.find(":first").css("marginRight"))+parseInt(elCont.find(":first").css("marginLeft")));
            //alert(newLeft);
            //alert(newLeft);
            elCont.animate({
                left : newLeft
            }, 600, function(){
                //alert(elCont);
                slideBind();
            });
        };
        var slideBind = function(){
            navi.find(".foward").click(function(){
                slideUnbind();
                slideFoward();
                return false;
            });
            navi.find(".back").click(function(){
                slideUnbind();
                slideBack();
                return false;
            });
        };
        var slideUnbind = function(){
            navi.find("a").unbind();
        };
        init();
        return this;
    };
    $('.slider').infinteSlider({
        focusFrame : ".slider-navi",
        infiniteMode : true
    });
    
    $('.room_slider').each(function(){
        $(this).infinteSlider({
            infiniteMode : true
        });
    });
    $.wdbox.settings.window_title = "";
    $.wdbox.settings.window_interaction = "<a class = 'closeLink'>Close</a>";

    $(".ajaxPicture").live("click", function(){
        var href = $(this).attr("href");
        $.wdbox.alert("<img class='picf' src='"+href+"'/>");
        
        $(".wdbox .picf").load(function(){
            var picw = $(".wdbox .picf").width();
            $(".wdbox .wdbox_content").width(picw);
            $.wdbox.centerBox({
                top : 50
            });
        });
        return false;
    });

}); // end document.ready call
