// JavaScript Document
(function($){ $.fn.dynamicRotator = function(options){
	var defaults = {
		interval: 2000,
		transition: "fading",
		width:100,
		height:100,
		callBack:null
	};
	
	var options = $.extend(defaults, options);
	return this.each(function(index) {
		var s_item;				  
		var items = [];
		var cnt = $(this).children().size();
		var	ctr = 0;
		var _parentM = $(this);
		$(this).children().each(function(index,item){
			items[ctr] = $(item);
			ctr++;
		});
		ctr = 0;
		
		var fading = function(){
			_parentM.children().each(function(index,item){
				if($(item).is(":visible")){
					$(item).fadeOut();		
				}
			});
			
			if((ctr + 1) < cnt){
				items[ctr + 1].fadeIn("slow");
				ctr = ctr + 1;
			}else{
				items[0].fadeIn("slow");
				ctr = 0;
			}
			if(options.callBack != null){
				eval(options.callBack)(items[ctr]);	
			}
		};
		
		setInterval(
			function(){
				eval(options.transition)();
			}, 
			options.interval
		);
	});
}})(jQuery);



function init_dw_Scroll_center() {
	var wndo = new dw_scrollObj('sub-content-frame', 'scroll');
	wndo.setUpScrollbar("cdragBar", "ctrack", "v", 0, 0, false);
	wndo.setUpScrollControls('sub-content-frame');
}

function init_dw_Scroll_home() {
	var wndo = new dw_scrollObj('home_dr_content', 'scroll');
	wndo.setUpScrollbar("cdragBar", "ctrack", "v", 0, 0, false);
	wndo.setUpScrollControls('home_dr_content');
}

jQuery(document).ready(function() {
	
	$("#rotatorbanner, .about_us_rotator").dynamicRotator({interval:5000});
	
	jQuery.noConflict();

	jQuery(".sidebar-nav .menu li a").not(".sidebar-nav .menu li ul li a").click(
		function(){
			var _next = jQuery(this).next("ul"); 
			var parent= jQuery(this).parent();
			jQuery("ul.sub-menu:visible").not(_next).slideToggle("slow");
			_next.slideToggle("slow",function(){
				jQuery(".sidebar-nav .menu li.current-menu-parent").removeClass("current-menu-parent");
				parent.addClass("current-menu-parent");
			}); 
			
			if(_next.is("ul")){
				return true
			}
		}
	);
	/*init_dw_Scroll_center = function () {
		var wndo = new dw_scrollObj('home_dr_content', 'scroll');
		wndo.setUpScrollbar("cdragBar", "ctrack", "v", 0, 0, false);
		wndo.setUpScrollControls('home_dr_content');
	}
	init_dw_Scroll_center();*/
	
	jQuery(".code_input-text").click(
		function(){
			if(jQuery(this).val() == jQuery(this).attr("title")){
				jQuery(this).val("");	
			}
		}
	
	);
	jQuery(".code_input-text").blur(
		function(){
			if(jQuery(this).val() == ""){
				jQuery(this).val(jQuery(this).attr("title"));	
			}
		}					
	);
	
	
	jQuery("#btn-photo-slider-next, .btn-photo-slider-next").click(
		function(){
			var _slider = jQuery(".photo-thumbs",jQuery(this).parent());
			var nML3 = (parseInt(_slider.css("marginLeft")) - 298) * (-1);
			var aWidth3 = (jQuery(".inner-cont",_slider ).length * 298);
			if(aWidth3 > nML3){
				_slider.animate({"marginLeft": "-=298"}, 400);
			}else{
				_slider.animate({"marginLeft": "0px"}, 400);	
			}
			return false;
		}
	);
	jQuery("#btn-photo-slider-prev, .btn-photo-slider-prev").click(
		function(){
			var _slider = jQuery(".photo-thumbs",jQuery(this).parent());
			var nML3 = (parseInt(_slider.css("marginLeft")) + 298) * (-1);
			var aWidth3 = (((jQuery(".inner-cont",_slider ).length * 298) - 297) * (-1));
			if(nML3 > -1){
				_slider.animate({"marginLeft": "+=298px"}, 400);
			}else{
				_slider.animate({"marginLeft": aWidth3 + "px"}, 400);	
			}
			return false;
		}
	);
	
	jQuery('#slider1').tinycarousel({
		controls: false,
		pager: true, 
		interval: true,
		intervaltime: 6000
	});	
});

function focusField(obj) {
	
}

function blurField(obj) {
	
}

jQuery(document).ready(function() {
	
	jQuery("a").each(function(index){
	    var home_url = "http://www.mansfieldcosmeticsurgery.com";
		if (this.href.indexOf('http://')>=0) {
			if (this.href.indexOf(home_url)<0) {
				//alert(this.href);
				jQuery(this).attr('target','_blank');
			}
		}
	});
	
	jQuery(".click-to-call a").fancybox({
		'titlePosition' : 'inside',
		'padding' : 0,
		'transitionIn' : 'fade',
		'transitionOut' : 'fade'
	});	
	
	jQuery("#click-to-call-form form").live('submit',function() {
	//jQuery("#click-to-call-form").submit(function(){		
		var _form = jQuery(this);
		var _url = _form.attr('action');
		var _data = _form.serialize() + '&ajax=click-to-call-form';
		
		
		jQuery("span.error",_form).html('').hide();
		
		jQuery(".output_msg", _form)
		//.css("display","none")
		.html("Sending data. Please wait...")
		.fadeIn("fast");
		jQuery.getJSON(_url,_data,function(data){
			
			jQuery("span.error",jQuery("#c2c_name").parent()).hide();
			jQuery("span.error",jQuery("#c2c_phone").parent()).hide();
			jQuery("span.error",jQuery("#c2c_email").parent()).hide();
			jQuery("span.error",jQuery("#c2c_comment").parent()).hide();
			jQuery("span.error",jQuery("#c2c_code").parent()).hide();
			if (data.name != undefined) {
				jQuery("span.error",jQuery("#c2c_name").parent()).html(data.name).show();
			}
			if (data.phone != undefined) {
				jQuery("span.error",jQuery("#c2c_phone").parent()).html(data.phone).show();
			}
			if (data.email != undefined) {
				jQuery("span.error",jQuery("#c2c_email").parent()).html(data.email).show();
			}
			if (data.comment != undefined) {
				jQuery("span.error",jQuery("#c2c_comment").parent()).html(data.comment).show();
			}
			if (data.code != undefined) {
				jQuery("span.error",jQuery("#c2c_code").parent()).html(data.code).show();
			}
			
			jQuery(".output_msg", _form).html((data.success==false)?'':data.success)
				.delay(3000)
				.fadeOut("slow");	
					
			if (data.success) {

				jQuery("input[type=text], textarea", _form).each(
					function(index,item){
						jQuery(item).val(jQuery(item).attr("title"));
					}
				);
		   }
		});

		return false;
	});	
	
	jQuery(".consultation-form .input-text").focus(function(){
		if ( jQuery(this).val() == jQuery(this).attr("title") ) {
			jQuery(this).val("");
		}
	});

	jQuery(".consultation-form .input-text").blur(function(){
		if ( jQuery(this).val() == "" ) {
			jQuery(this).val(jQuery(this).attr("title"));
		}
	});
	
	jQuery("#consultation-form").submit(function(){
		var _form =  jQuery(this);
		var _url = jQuery(this).attr("action");
		var _data = jQuery(this).serialize() + "&ajax=consultation_form";
		
		jQuery(".msg", _form)
		.css("display","none")
		.html("<p class='info'>Sending data. Please wait...</p>")
		.fadeIn("slow");
			
		jQuery.ajax({
			type: 'POST',
			url: _url,
			data: _data,
			success: function(msg){
				jQuery(".msg", _form).html(msg)
				.delay(3000)
				.fadeOut("slow");
				
				if(msg.indexOf("<!--RESET-->") > -1){
				   jQuery("input[type=text], textarea", _form).each(
						function(index,item){
							jQuery(item).val(jQuery(item).attr("title"));
						}
				   );
				}
			}
		});
							
		return false;
	});
	
	jQuery("#contact-form").submit(function(){
		var _form =  jQuery(this);
		var _url = jQuery(this).attr("action");
		var _data = jQuery(this).serialize() + "&ajax=contact_form";
		
		jQuery(".msg", _form)
		.css("display","none")
		.html("<p class='info'>Sending data. Please wait...</p>")
		.fadeIn("slow");
			
		jQuery.ajax({
			type: 'POST',
			url: _url,
			data: _data,
			success: function(msg){
				jQuery(".msg", _form).html(msg)
				.delay(3000)
				.fadeOut("slow");
				
				if(msg.indexOf("<!--RESET-->") > -1){
				   jQuery("input[type=text], textarea", _form).each(
						function(index,item){
							jQuery(item).val(jQuery(item).attr("title"));
						}
				   );
				}
			}
		});
							
		return false;
	});	

	jQuery('#home-slider').liteAccordion({
			onActivate : function() {
				this.find('figcaption').fadeOut();
			},
			slideCallback : function() {	
				this.find('figcaption').fadeIn();
			},
			headerWidth: 34,
			containerWidth : 940,
			containerHeight : 345,			
			autoPlay : true,
			pauseOnHover : true,
			theme : 'basic',
			rounded : false,
			enumerateSlides : true					
	}).find('figcaption:first').show();
	
	jQuery(".gallery-photo a[rel=gallery-photo]").fancybox({
		'titlePosition' : 'inside',
		'padding' : 0,
		'transitionIn' : 'fade',
		'transitionOut' : 'fade'
	});

});	
