// JavaScript Document

// ....................FUNCTIONS

function subCatHeaders()
{
// Add sub catagories animated sliders for client services						   
var mastheadIMG = ['',
				   'images/transportationIMG.jpg',
				   'images/personalLines.jpg',
				   'images/defect.jpg',
				   'images/workers.jpg',
				   'images/liability.jpg',
				   'images/cproperty.jpg',
				   'images/energyRelated.jpg',
				   'images/runOff.jpg'
				   ];
var animIMG = [
			   '',
			   'images/AnimTransportation.png',
			   'images/AnimPersonalLines.png',
			   'images/AnimDefect.png',
			   'images/AnimWorkers.png',
			   'images/AnimLiability.png',
			   'images/AnimCproperty.png',
			   'images/AnimEnergyRelated.png',
			   'images/AnimRunOff.png'
			   ]; 

$("#accordion h3 a").each(function(i){

$(this).click(function() {
$("#mainMasthead").css({ 'background' :  'url('+mastheadIMG[i]+') no-repeat scroll 0 0 transparent'});
$("#mainAnim").html('<img width="1000px" height="39px" src="'+animIMG[i]+'">');
$("#mainAnim").css({'width' :  '0px', 'marginLeft' : '1000px'});
$("#mainAnim").animate({'width' :  '1000px', 'marginLeft' : '0px' }, 2000);

});

});						   
// end animate 
}
	
	
	 
$(document).ready(function(){
						   
$('.fixPNG').supersleight({shim: 'images/x.gif'});
$('.fixPNG').supersleight();
$('img').supersleight({shim: 'images/x.gif'});
$('img').supersleight();



// add body mod for claims cube download
$("#agreeToCube").css({"display" : "none"});

$(".downloadCube a").click(function(){
		
		$("#agreeToCube").dialog({
			resizable: true,
			height:500,
			width:850,
			modal: true,
			buttons: {
				'Accept user agreement and download': function() {
					window.location = "http://claims.narisk.com:8080/claims3-narisk/c3.jnlp";
					$(this).dialog('close');
				},
				Cancel: function() {
					$(this).dialog('close');
				}
			}
		});
	});

						   
//.......................................... Accordion
$("#accordion").accordion({ header: "h3",autoHeight: false, active:false});
$("#accordion div:first").hide();


// setup according sub navagation area
var getAllCats = [];
$("#servicesBoth div").each(function(){
getAllCats.push($(this).attr('id'));
});

$("#accordion a").each(function(i){
$(this).addClass(getAllCats[i]);
});

var i =0;
 $("#servicesBoth div").not("#"+getAllCats[0]).hide();

$("#accordion a").each(function(i){

$(this).click(function() {
$("#servicesBoth div").show();
    $("#servicesBoth div").not("#"+getAllCats[i]).hide();
}); // end click
// add hover style for selected
$("#accordion li a").click(function() {
$("#accordion li a").removeAttr("style");
$(this).css({ "color" : "#ffffff", "background" : "#000 url(../images/accordPoint.jpg) no-repeat right center"});
return false;
}); // end click end hover selected



// add click event to deselect hover state when leaving cat
$("#accordion h3 a").click(function() {
$("#accordion li a").removeAttr("style");
});
// end
}); // end each
// add height to div that fall short of425px

$("#accordion a").each(function(i){
$(this).click(function() {
var myHeight = $("#"+getAllCats[i]).height();
if(myHeight < 460) { 
$("#mainContent").height("530px"); 
} else {
$("#mainContent").height(myHeight+89); 
}
// end add height
}); // end click
});



// trigger on ie6 for transparent issue						   
// if  ($.browser.msie && $.browser.version == '6.0') {correctPNG()};
 
 // fade in main mast head and slide in from left title
														 
$("#mainAnim").animate({'width' :  '1000px', 'marginLeft' : '0px'}, 2000);			 											 



// add active hover state to tab 

	// get location
	var myLocation = window.location.href.slice(window.location.href.indexOf('?') + 1).split('/');
	
	
	switch(myLocation[3])
{
		case "contacts.php":
				$("#navigation a.contacts").css({"backgroundPosition" : "-899px -90px"});
		  break;
		case "newsEvents.php":
				$("#navigation a.newsEvents").css({"backgroundPosition" : "-756px -90px"});
			  break;
		case "resources.php":
				$("#navigation a.resources").css({"backgroundPosition" : "-649px -90px"});
			  break;
		case "partnerEtools.php":
				$("#navigation a.partnerEtools").css({"backgroundPosition" : "-497px -90px"});
			   break;
		case "additionalServices.php":
				$("#navigation a.additionalServices").css({"backgroundPosition" : "-315px -90px"});
			  break;
			case "claimsServices.php":
				$("#navigation a.claimsServices").css({"backgroundPosition" : "-165px -90px"});
				subCatHeaders();
			  break;
		case "aboutUs.php":
				$("#navigation a.aboutUs").css({"backgroundPosition" : "-69px -90px"});
			  break;
			case "index.php":
				$("#navigation a.home").css({"backgroundPosition" : "0px -90px"});
				break;
			case "":
				$("#navigation a.home").css({"backgroundPosition" : "0px -90px"});
			
		default:
}
	
				
// main nav rollovers
	      if ($.browser.msie && $.browser.version < 7) return;
        
        $('#navigation li')
            .removeClass('highlight')
            .find('a')
            .append('<span class="hover" />').each(function () {
                    var $span = $('> span.hover', this).css('opacity', 0);
                    $(this).hover(function () {
                        // on hover
                        $span.stop().fadeTo(500, 1);
                    }, function () {
                        // off hover
                        $span.stop().fadeTo(500, 0);
                    });
                });
			

				
//hover states on the static widgets
$('#dialog_link, ul#icons li').hover(
	function() { $(this).addClass('ui-state-hover'); }, 
	function() { $(this).removeClass('ui-state-hover'); }
);


// function for resources page add even odd gray bars abd logo hover

function addBars(mydiv) {

$("#"+mydiv+" tr:even").css({"backgroundColor" : "#ceb26d"});

$("#"+mydiv+" tr td a").hover(
function() {
$(this).prepend('<img src=\"images/assoHoverLogo.png\" width=\"19\" height=\"19\" alt=\"Hover logo\">').css({"text-decoration" : "underline"});
},
function() {
$("#"+mydiv+" tr td a img").remove();
$(this).css({"text-decoration" : "none"})
});

};	// end resource function
//  add bars for resource page

addBars("general");
addBars("transportation");
addBars("workersCompensation");
addBars("constructionDefect");
addBars("property");
addBars("fraud");



// News and Events page

// add pdf icons and style rigntNews div

$("#rightNews li a").prepend('<div><img src=\"images/newsPDFIcon.jpg\" width=\"19\" height=\"19\" alt=\"Hover logo\"></div>').css({
"color" : "#8c0c04",
"fontWeight" : "bold"
});

$("#rightNews li a img").css({
"margin" : "7px 18px 4px 0px", 
"border" : "0",
"float" : "left"
});

rightNewsHT = $("#rightNews").height();
if(rightNewsHT<400) {$("#rightNews").height(420)};


// hover

$("#rightNews li a").hover(
function()
{
$(this).css({"color" : "#000000", "text-decoration" : "underline"});
}, 
function()
{$(this).css({"color" : "#8c0c04", "text-decoration" : "none"});
});

// end style pdf news



// Contact page

//  form val 
$(function() {
  $('.error').hide();
  $('input[type=text]').css({backgroundColor:"#FFFFFF"});
  $('input[type=text]').focus(function(){
    $(this).css({backgroundColor:"#FFDDAA"});
  });
  $('input[type=text]').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });

  $(".button").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
		
	  var name = $("input#name").val();
		if (name == "") {
      $("label#name_error").show();
      $("input#name").focus();
      return false;
    }
	var phone = $("input#phone").val();
		if (phone == "") {
      $("label#phone_error").show();
      $("input#phone").focus();
      return false;
    }	
		var email = $("input#email").val();
		if (email == "") {
      $("label#email_error").show();
      $("input#email").focus();
      return false;
    }
		var checked = $('input[type=checkbox]:checked').val() != undefined;
		if(checked == true){
		$("input:checkbox:checked").val('yess');
	}		
	var newsletter = $("input#newsletter").val();

		var comment = $("textarea#comment").val();

		var dataString = 'name='+ name + '&phone=' + phone + '&email=' + email + '&newsletter=' + newsletter + '&comment=' + comment;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "process.php", 
      data: dataString,
      success: function() {
        $('#formWrap').html("<div id='message'></div>");
        $('#message').html("<h2>Contact Form Submitted!</h2>")
        .append("<p>Thank you " + name + "</p>")
        .append("<p>We will be in touch soon.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<img id='checkmark' src='images/check.png' />");
        });
      },
	    error: function(){
        $('#message').html("<h2>Contact Form not submitted! Please contact us.</h2>");
  }

     });
    return false;
	});
});








			}); // end ready

