$(document).ready(function(){

	version = parseFloat(navigator.appVersion.split("MSIE")[1]);
	if(version <= 8) {
		/*
		$('#sidebar').corner({
			tl: { radius: 10 }, tr: { radius: 10 }, bl: { radius: 10 }, br: { radius: 10 }, antiAlias: true 
		});
		$('#sidebar h3').corner({
			tl: { radius: 10 }, tr: { radius: 10 }, bl: { radius: 0 }, br: { radius: 0 }, antiAlias: true 
		});
		$('header').corner({
			tl: { radius: 10 }, tr: { radius: 10 }, bl: { radius: 10 }, br: { radius: 10 }, antiAlias: true 
		});
		$('#home_footboxes li a').corner({
			tl: { radius: 10 }, tr: { radius: 10 }, bl: { radius: 10 }, br: { radius: 10 }, antiAlias: true 
		});
		$('ul#inner_sidemenu').corner({
			tl: { radius: 10 }, tr: { radius: 10 }, bl: { radius: 10 }, br: { radius: 10 }, antiAlias: true 
		});
		$('ul#subpages li a').corner({
			tl: { radius: 10 }, tr: { radius: 10 }, bl: { radius: 10 }, br: { radius: 10 }, antiAlias: true 
		});
		*/
	}
	
	if(jQuery().fancybox) 
	{
		//jQuery plugin exists
		$("a.map").click(function() {
		
			$.fancybox({
				'padding'		: 10,
				'type'				: 'iframe',
				'href'				: 'http://maps.google.co.uk/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=Gu10+1PX&amp;aq=&amp;sll=53.800651,-4.064941&amp;sspn=19.563564,39.506836&amp;ie=UTF8&amp;hq=&amp;hnear=Farnham+GU10+1PX,+United+Kingdom&amp;z=14&amp;ll=51.214063,-0.74813&amp;output=embed"></iframe><br /><small><a href="http://maps.google.co.uk/maps?f=q&amp;source=embed&amp;hl=en&amp;geocode=&amp;q=Gu10+1PX&amp;aq=&amp;sll=53.800651,-4.064941&amp;sspn=19.563564,39.506836&amp;ie=UTF8&amp;hq=&amp;hnear=Farnham+GU10+1PX,+United+Kingdom&amp;z=14&amp;ll=51.214063,-0.74813'
			});
			
			return false;
		});
	
		$(".iframe").fancybox();
	} else {
		//jQuery plugin DOES NOT exist
	}
		
	var $dButtons = {};
	var $contactusdialog = $("<div></div>")
	.html('<div id="sucmsg">Thank you, your details were sucessfully sent!</div>\
		<div id="ldr"></div>\
		<div id="popf">\
		<thead>\
			<tr class="ui-widget-header ">\
				<th width="70" style="font-size:11px;padding:10px;"><BR>As you browse our services we hope you get a strong flavour of what PurpleJelly are all about.  We know we sit in a crowded sector and so you have plenty of choice. However, we think we\'re quite different from the rest with our down-to-earth, professional but friendly \'partnership\' approach. Our client base is wide and extremely interesting; and the companies we work with can be anything from super-small, to medium-sized, with around 500 people needing support. We listen hard and talk to people in plain English - something many of our competitors find difficult to do. Take a bite - you\'ll be wanting more!</br></br></th>\
			</tr>\
		</thead>\
		<form id="popupcontactfrm">\
			<fieldset>\
			<ol>\
				<li>\
					<label for="popname">Your Name:</label>\
					<input id="popname" name="popname" placeholder="Your Name" required autofocus />\
				</li>\
				<li>\
					<label for="popemail">Your Email:</label>\
					<input id="popemail" name="popemail"  type="email" placeholder="anything@example.com" required />\
				</li>\
				<li>\
					<label for="popphone">Phone:</label>\
					<input id="popphone" name="popphone"  type="text"  placeholder="Phone" required />\
				</li>\
				<li>\
					<label for="popcompany">Company:</label>\
					<input id="popcompany" name="popcompany"  type="text"  placeholder="Company" required />\
				</li>\
				<li class="reverse">\
					<input id="popnewsletter" name="popnewsletter" type="checkbox" />\
					<label for="popnewsletter">Please send me a copy of the Purplejelly newsletter. (tick to receive):</label>\
				</li>\
			</ol>\
		</fieldset>\
		</form>\
		</div>')
	.dialog({
		autoOpen: false,
		width: 550,
		height: 550,
		modal: true,
		overlay: {
			backgroundColor: '#000',
			opacity: 0.5
		},
		buttons: {
			"Submit": function() { 	

				t = $(this);
			
				//get data
				name = $('#popname').val();
                email = $('#popemail').val();
                phone = $('#popphone').val();
                company = $('#popcompany').val();  
                newsletter = $('#popnewsletter').val();  
				
				parameters = { name: name, email: email, phone: phone, company: company, newsletter: newsletter }
				
				//hide form and show loading
				$('#ldr').show();
				$('#popf').hide();
				//resize window to loading
				//$(this).parent().animate({'width': 300, 'height' : 300}, 500);	
				
				$.ajax({
					//url: "/wp-content/themes/purplejelly/contact.php",
					//url: $baseURL + "/send.php",
					url: "send.php",
					type: "POST",
					data: parameters,
					success: function(){
						
						//remove buttons and just have ok
						$contactusdialog.dialog({ buttons: { "Ok": function() { $(this).dialog("close"); } } });
					
						//alert('Submit successful');
						//$contactusdialog.dialog("close"); 
						$('#ldr').hide();
						$('#popf').hide();
						$('#sucmsg').show();
					},
					error: function(){
						//t.parent().animate({'width': 100, 'height' : 100}, 500);	
						$('#ldr').hide();
						$('#sucmsg').hide();
						$('#popf').show();
						alert('Error there was a problem sending your email, please try again');
						//$contactusdialog.dialog("close"); 
					}
				});
			}, 
			"Cancel": function() { 
				$(this).dialog("close"); 
			} 
		},
		close: function() {
			$(this).dialog({ buttons: $dButtons });
			$('#ldr').hide();
			$('#sucmsg').hide();
			$('#popf').show();
		},
		title: "Take a Bite - you won't be disappointed!"
	});
	
		
	var $trenddialog = $("#popup_trend").dialog({
			modal: true,
			autoOpen: false,
			buttons: {
				Ok: function() {
					$( this ).dialog( "close" );
				}
			}
	});
	

	$('ul#home_footboxes li a').css({'opacity': 0.7});
	$('ul#home_footboxes li a').hover(function() {
		$(this).animate({'opacity': 1}, 500);
	},function() {
		$(this).animate({'opacity': 0.7}, 500);	
	});
	
	$('#bite').click(function() {
		$dButtons = $contactusdialog.dialog('option', 'buttons');
		$contactusdialog.dialog('open');
		return false;
	});
	
	$('ul#menu-side li').click(function() {
	
		//$('#popup_trend').html('<div align="center"><img src="img/loading.gif" /></div>');
	
		//link = $(this).find('a').attr('href');	
		//$('#popup_trend').load(link+" .entry");
	   
		t = $(this).find('a').attr('title');
		$('#popup_trend').html(t);
	   
		$trenddialog.dialog('open');
	
		return false;
	});
	
		
	$('#supportplans ul li a').click(function() {
		$('#supportplans ul li a').removeClass("active");
		$(this).addClass("active"); 
		
		var html = $(this).parent().find('div').html();
		$('.spcontent').html(html);
		return false;
	});
	
	//$('.slalink').click(function() {
	$('.slalink').live('click',function() {
		//$sladialog.dialog('open');
		//$('#sladiag').dialog('open');
		
		
		var $sladialog = $("<div id=\"sladiag\"></div>")
		.html('<table id="sla" class="ui-widget ui-widget-content">\
		<thead>\
			<tr class="ui-widget-header ">\
				<th width="70" style="font-size:11px;padding:10px;">Priority</th>\
				<th style="font-size:11px;padding:10px;">Affected Service</th>\
				<th width="80"style="font-size:11px;padding:10px;">1st Response</th>\
				<th width="100" style="font-size:11px;padding:10px;">Call to site</th>\
			</tr>\
		</thead>\
		<tbody>\
			<tr>\
				<td>Priority 1</td>\
				<td>Network / Server outage</td>\
				<td>&lt; 60 Minutes</td>\
				<td>&lt; 2 Working Hours</td>\
			</tr>\
			<tr>\
				<td>Priority 2</td>\
				<td>Serious Network / Server issues including Internet connectivity</td>\
				<td>&lt; 90 Minutes</td>\
				<td>&lt; 4 Working Hours</td>\
			</tr>\
			<tr>\
				<td>Priority 3</td>\
				<td>Minor Network / Server issues / Unable to carry out normal work</td>\
				<td>&lt; 120 Minutes</td>\
				<td>&lt; 8 Working Hours</td>\
			</tr>\
			<tr>\
				<td>Priority 4</td>\
				<td>Non critical issues and enquiries</td>\
				<td>&lt; 1 Work Day</td>\
				<td>&lt; 3 Work Days or as agreed</td>\
			</tr>\
		</tbody>\
		</table>').dialog({
			autoOpen: true,
			width: 550,
			height: 300,
			modal: true,
			overlay: {
				backgroundColor: '#000',
				opacity: 0.5
			},
			buttons: {
				"Ok": function() { 
					$(this).dialog("destroy"); 
				} 
			},
			title: "Service Level Agreement"
		});
		
		
		return false;
	});
	
	$("nav ul li:last").addClass("last");
	
});

$(window).load(function() {
    $('#slider').nivoSlider({
		effect: 'fade',
		directionNav:true,
		directionNavHide: false,
		controlNav:false
	});
});
