
$(function(){

	$("#twitter").getTwitter({
		userName: "coolminds",
		numTweets: 2,
		loaderText: "Loading tweets...",
		slideIn: true,
		showHeading: false,
		headingText: "Latest Tweets",
		showProfileLink: false
	});

	$('.slideshow1').cycle({
		fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
	});

	$('.slideshow2').cycle({
		fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
	});

	$('.slideshow3').cycle({
		fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
	});

    $('.slideshow1').hover(
        function() { $('.slideshow1').cycle('pause'); },
        function() { $('.slideshow1').cycle('resume'); }
    );
    $('.slideshow2').hover(
        function() { $('.slideshow2').cycle('pause'); },
        function() { $('.slideshow2').cycle('resume'); }
    );
    $('.slideshow3').hover(
        function() { $('.slideshow3').cycle('pause'); },
        function() { $('.slideshow3').cycle('resume'); }
    );
    /*
    $('.opportunityDivMore').append("<p class='largeDarkFont'>Coolminds Technologies (P) Ltd., Infopark, Kochi is partnering with Incomm a 300 million USD company based in Atlanta, USA for supporting its e-commerce platforms from Cochin/Bangalore/Chennai.</p>");
	var emailStr = "<div><br/><p class='largeDarkFont'>Interested candidates who match the following profile send their resumes to :</p><img src='site/dyn/mailCareer.gif' alt='coolminds'/></div>";
	$('.opportunityDivMore').append(emailStr);
    $.get("site/opportunities.txt", function(data){
    	var mystring = data;
    	$.each( mystring.split("$"), function(index, item){
    			var values = this.split("%");
    			var slNo = index + 1 ;
    			var positionTitle = "<br/><div style='color:#E39096;height:20px;'><h4><font color='#E39096'>" + slNo + " ) "  +values[0] + "</font></h4><br/></div>";
    			var positionInfo = "";
    			var cnt = 0;
    			$.each( this.split("%"), function(){
    				if(cnt != 0){
    					positionInfo = positionInfo + "<div style='color:#3F3A3A'><p class='largeDarkFont'>" + this + "</p></div>";
    				}
    				cnt = cnt + 1;
    			})

    			var opportunity = "<div>" + positionTitle + positionInfo + "</div>";
		        $('.opportunityDivMore').append(opportunity);
        })
	});
	*/
    $('.opportunityDivMore').append("<div><p class='largeDarkFont'>If you are interested in working with us, please send an e-mail to :</p><img src='site/dyn/mailCareer.gif'></img></div>");
	
    //variable to reference window
    $myWindow = jQuery('.opportunityDivMore');
    $myWindow.dialog({ height: 220,
            width: 750,
           modal: true,
           position: 'center',
           autoOpen:false,
          title:'Opportunities', 
          hide:'slide',           
         overlay: { opacity: 0.4, background: 'black'}
         });


     $myChatWindow = jQuery('.chatWindowDiv');
     $myChatWindow.dialog({ height: 350,
        width: 650,
        modal: false,
        draggable: true,
        position: 'center',
        autoOpen: false,
        title:'Cool Chat!',
        hide:'slide',
        overlay: { opacity: 0.4, background: 'black'}
        });
     /*
    // Routing to respective pages based on URL
    var targetPage = "home";
	var path = jQuery.url.attr("query");
	if(path != null){
		var startIndex = path.lastIndexOf("page=");
		if(startIndex != -1){
			targetPage = path.substring(startIndex+5);
		}
	}

     if(targetPage.match('services')){
     	showServices();
     }else if(targetPage.match('contact-us')){
     	showContact();
     }else if(targetPage.match('about-us')){
     	showAbout();
     }else if(targetPage.match('careers')){
    	
     	showOpportunity();
     }else{
     	showHome();
     }
	*/

});

//function to show dialog
var showDialog = function() {
    $myWindow.show();
    $myWindow.dialog("open");
}

function showOpportunity(){
	showDialog();
}

function showHome(){
	$("#coolAbout").css("display","none");
	$("#coolServices").css("display","none");
	$("#coolContact").css("display","none");
	$('.opportunityDivMore').css("display","none");
	$("#left_column").css("display","block");

}

function showAbout(){
	$("#left_column").css("display","none");
	$("#coolServices").css("display","none");
	$("#coolContact").css("display","none");
	$('.opportunityDivMore').css("display","none");
	$("#coolAbout").css("display","block");
}

function showServices(){
	$("#left_column").css("display","none");
	$("#coolAbout").css("display","none");
	$("#coolContact").css("display","none");
	$('.opportunityDivMore').css("display","none");
	$("#coolServices").css("display","block");
}

function showContact(){
	$("#left_column").css("display","none");
	$("#coolServices").css("display","none");
	$("#coolAbout").css("display","none");
	$('.opportunityDivMore').css("display","none");
	$("#coolContact").css("display","block");

	// Clear fields
	$("#textfield").val("");
	$("#textfield2").val("");
	$("#textfield3").val("");
	$("#textarea2").val("");
	$("#MailStatusDiv").html("");
}

function showChatWindow(){
    $myChatWindow.show();
    $myChatWindow.dialog("open");
}

function sendContactDetails(){
	var name = $("#textfield").val();
	var email = $("#textfield2").val();
	var subject = $("#textfield3").val();
	var message = $("#textarea2").val();
	var comma = $("#comma").val();

	var validationStr = "Sorry. ";
	var valid = 1;
	if(! checkemail(email)){
		validationStr = validationStr + "Incorrect e-mail. ";
		valid = 0;
	}
	if(subject == "" || message == ""){
		validationStr = validationStr + "Required fields should not be blank. ";
		valid = 0;
	}

	$("#MailStatusDiv").css("display","block");
	if(valid == 0){		
		$("#MailStatusDiv").html("<font color='red'>" + validationStr + "</font>");
		return;
	}else{
		$("#MailStatusDiv").html("<img src='site/img/loading1.gif'></img>");
		setTimeout(function() { 
			$("#MailStatusDiv").html("<font color='green'>Thanks for getting in touch with us.</font>");
		}, 3000);		
	}

	var url = "http://www.coolmindsinc.com/cool_php/coolMail2.php";
	$.ajax({
		type: "POST",
   		url: url,
   		dataType:"json",
   		data: {'textfield':name,'textfield2':email,'textfield3':subject,'textarea2':message,'comma':comma},
   		success: function(msg){
   			showHome();
   		}
 	});
}


function checkemail(email)
{
	var str= email;
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(str)){
		return true;
	}else{
		return false;
	}
}

function sendReference(){
	var email = $("#referenceMail").val();
	var validationStr = "";
	$("#ReferenceStatusDiv").css("display","block");
	if(! checkemail(email)){
		validationStr = "Invalid mail address.";
		$("#ReferenceStatusDiv").html("<font color='red'>" + validationStr + "</font>");
		return;
	}else{
		$("#ReferenceStatusDiv").html("<img src='site/img/loading1.gif'></img>");
		setTimeout(function() { 
			$("#ReferenceStatusDiv").html("<font color='green'>Thank You.</font>");		
		}, 3000);		
	}	

	var url = "http://www.coolmindsinc.com/cool_php/coolReferenceMail.php";
	$.ajax({
		type: "POST",
   		url: url,
   		dataType:"json",
   		data: {'referenceMail':email},
   		success: function(msg){

   		}
 	});
}
