var images = new Array();
 
function preloadImages(){
    for (i=0; i < preloadImages.arguments.length; i++){
         images[i] = new Image();
        images[i].src = preloadImages.arguments[i];
    }
}

stuHover = function() {
	var cssRule;
	var newSelector;
	for (var i = 0; i < document.styleSheets.length; i++)
		for (var x = 0; x < document.styleSheets[i].rules.length ; x++)
			{
			cssRule = document.styleSheets[i].rules[x];
			if (cssRule.selectorText.indexOf("LI:hover") >= 0)
			{
				 newSelector = cssRule.selectorText.replace(/LI:hover/gi, "LI.hover");
				document.styleSheets[i].addRule(newSelector , cssRule.style.cssText);
			}
		}
	var getElm = document.getElementById("mainmenu").getElementsByTagName("LI");
	for (var i=0; i<getElm.length; i++) {
		getElm[i].onmouseover=function() {
			this.className+=" hover";
		}
		getElm[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" hover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", stuHover);


function add_your_clinic(){
	$.colorbox({'width' : 980, 'height' : 550, 'title' : true, iframe: true, overlayClose:false, href:"/addyourclinic"});	
}

function joinus_patient(){
	$.colorbox({'width' : 940, 'height' : 550, 'title' : true, iframe: true, overlayClose:false, href:"/lp/create"});	
}

function login_patient(){
	$.colorbox({'width' : 940, 'height' : 550, 'title' : true, iframe: true, overlayClose:false, href:"/login-pop-up/6"});	
}

function find_doctor_menu(){
	$.colorbox({'width' : 835, 'height' : 545, 'title' : true, iframe: true, overlayClose:false, href:"/psearch/index"});
}


function get_quick_links(){
	$("#quick_links_result").html('<img src="http://www.whereismydoctor.com/images/ajax-loader.gif" />');
	
	$.ajax({				
			type: "POST",
			url: "/query/get_quick_links",
			data: "skey="+$("#txt_quick_search").val(),
			success: function(msg){					
					$("#quick_links_result").html(msg);
					$("#quick_links").show();				
			}
		});		
}



$(document).ready(function() {
	
	init_contacts();
	//Social popup check
	
	try{
      if(page){
		  if(page=='home'){ 
			$.ajax({
		type: "POST",
		url: "/query/social_popup_check",
		success: function(data){
			if(data=='false'){
				setTimeout('open_social_popup();',10000);
				
			}
		   }
		 });
	}
	  }
	}catch(e){
		  
	}
	

	$('#find_submenu').load('/welcome_new/get_sub_menu');
	$('#guides_menu_holder').load('/welcome_new/get_guides_menu');
	$('#ask_menu_holder').load('/welcome_new/get_ask_menu');
	$('#news_menu_holder').load('/welcome_new/get_news_menu');
	
	$('#txt_tag_search').Watermark('dentist, tummy tuck, ABC clinic, Dr. Bob Smith');
	$('#txt_location_search').Watermark('Chicago, India, London, Ohio, 98027');
	$('#txt_quick_search').Watermark('Search');
	
	
	
	$('#txt_quick_search').focus(function(){
		$(this).animate({'width':140}, {
    duration: 150,
    specialEasing: {
      width: 'linear',
      height: 'easeOutBounce'
    }
	});
	});
	$('#txt_quick_search').blur(function(){
		$(this).animate({'width':100}, {
    duration: 150,
    specialEasing: {
      width: 'linear',
      height: 'easeOutBounce'
    }
	});
	});
	$('.psearch').colorbox({'width' : 835, 'height' : 545, 'title' : true, iframe: true, overlayClose:false, href:"/psearch/index"});
	
	$('body').click(function() {
		setTimeout("$('#quick_links').hide('fast')",300);
	});
	
	 $('#quick_links, #txt_quick_search').click(function(event){
		 event.stopPropagation();
	 });	
	
	$('.add_your_clinic').colorbox({'width' : 980, 'height' : 550,overlayClose:false, 'title' : true, iframe: true, overlayClose:false, href:"/addyourclinic"});	


 $.ajax({
	   		type: "POST",
	   		url: "/query/get_login_menu_new",
	   		success: function(data){
				$('#login').html(data);
 $('#join_us').qtip(
	  {
		 content: {
			text: '',
			url: '/query/get_tip/joinus_us',
			title: {
			   text: 'Join us',
			   button: '<img onclick="return false;" style="border:0;" src="/images/pc_del.png" alt="Close" />'
			}
		 },
		 position: {
			corner: {
			   target: 'bottomMiddle',
			   tooltip: 'topMiddle'
			},
			adjust: {
			   screen: true
			}
		 },
		 show: { 
			when: 'click', 
			solo: true
		 },
		 hide: 'unfocus',
		 style: {
			tip: true,
			border: {
			   width: 0,
			   radius: 4
			},
			name: 'light',
			width: 250,
			height: 40
		 }
	  });
	  
 $('#loginmenu').qtip(
	  {
		 content: {
			text: '',
			url: '/query/get_tip/loginmenu_us',
			title: {
			   text: 'Login',
			   button: '<img onclick="return false;" style="border:0;" src="/images/pc_del.png" alt="Close" />'
			}
		 },
		 position: {
			corner: {
			   target: 'bottomMiddle',
			   tooltip: 'topMiddle'
			},
			adjust: {
			   screen: true
			}
		 },
		 show: { 
			when: 'click', 
			solo: true
		 },
		 hide: 'unfocus',
		 style: {
			tip: true,
			border: {
			   width: 0,
			   radius: 4
			},
			name: 'light',
			width: 250,
			height: 40
		 }
	  });
			   }
			 });	
//	setTimeout('initialShowHideLikeSlider();',15000);
       
});
function init_contacts(){
	$('.contact_button').click(function(){
		$(this).attr("href","javascript:void(0);");
		open_popup_contact($(this).attr('clinic_details'));
	});
}
function open_social_popup(){
	$.colorbox({'width' : 840, 'height' : 520, 'title' : false, iframe: true, overlayClose:false, href:"/query/social_like_popup"});	
}
function open_popup_contact(vars){
	$.colorbox({'width' : 780, 'height' : 290, 'title' : true, iframe: true, overlayClose:false, href:"/phone_info/"+vars});	
}
function update_social(params, url, platform, action,type){
	if(url==undefined)
		url=params.href;
	if(type==undefined)
		type='like';
	if(platform==undefined)
		platform='google';
	if(params.state=='on' || action=='1')
		action='1';
	else
		action='-1';
	if(params.href!='' && params.href!=undefined){
		url=params.href;
	}
	$.ajax({				
			type: "POST",
			url: "/query/update_social_likes",
			data: "url="+url+'&platform='+platform+'&action='+action+'&type='+type+'&page='+window.location,
			success: function(msg){									
			}
		});		
}
function showHideLikeSlider(){
	if($('#sideBarLikeContents').is(":visible")){
		$('#sideBarLikeContents').hide('slow');
		$('#sideBarLikeTab img').attr('src',$('#sideBarLikeTab img').attr('src').replace(/-active(\.[^.]+)$/, '$1'));
	}else{
		$('#sideBarLikeContents').show('fast');
		$('#sideBarLikeTab img').attr('src',$('#sideBarLikeTab img').attr('src').replace(/(\.[^.]+)$/, '-active$1'));

	}
}
function initialShowHideLikeSlider(){
	if($('#sideBarLikeContents').is(":visible")){
	}else{
		showHideLikeSlider();
	}

}
