$(document).ready(function() {
	$('#messagebar').hide();
	setTimeout('$(".messagerow").slideUp()',5000);
	
	// shadows
	// $('.shadow').dropShadow({left: 0, top: 0, opacity: 1.0, blur: 4});
	
	// runtime data validation
		$('.numbersonly').keyup(function () { this.value = this.value.replace(/[^0-9]/g,''); });
		$('.lettersonly').keyup(function () { this.value = this.value.replace(/[^a-zA-Z\s\-]/g,''); });
	
	
	// cycle
		$('.cycle').cycle();
		$('.slidex').cycle({fx:'slideX'});
		$('.scrolldown').cycle({fx:'scrollDown'});
		$('.shuffle').cycle({fx:'shuffle',timeout:'5000'});
	
	// clearfix
	$('div').addClass('clearfix');
	$('ul').addClass('clearfix');
	$('li').addClass('clearfix');
	
	// focusbox
	
		// focusbox display pane
		$('ul.focusboxcontainer li#focusdisplaypane').hide();
		$('ul.focusboxcontainer li#focusdisplaypane a#close').live('click',function(){
			$('ul.focusboxcontainer li').fadeIn('fast');
			$('ul.focusboxcontainer li#focusdisplaypane').hide();
			$('ul.focusboxcontainer li a').removeClass('selected');
			return false;
		});
		
		// link click
		$('ul.focusboxcontainer li a').click(function(){
			$('ul.focusboxcontainer li a').removeClass('selected');
			$(this).addClass('selected');
			position=$(this).position();
			left=position.left;
			elementnumber=(left/150)+1;
			model=$(this).attr('href');
			modelid=$(this).attr('modelid')
			imgurl='display/images/focusbox/focusbox_profile_'+model+'.jpg';
			imghtml='<img src="'+imgurl+'" alt="'+model+'" />';
			imghtml=imghtml+'<a href="#" id="close">&laquo; close</a>';
			imghtml=imghtml+'<a href="node.php?id='+modelid+'&product='+model+'" id="details">details &raquo;</a>';
			$('ul.focusboxcontainer li').not($(this).parent()).fadeOut('fast');
			$('ul.focusboxcontainer li#focusdisplaypane').fadeIn('slow');
			$('ul.focusboxcontainer li#focusdisplaypane').html(imghtml);
			return false;
		});
	
	// node page
		$('#maincontent #leftcol #leftcontentpane #specs').hide();
		$('#maincontent #leftcol #leftcontentpane #contact').hide();
		
		// tabs
		$('#tabs a').click(function(){
			$('#tabs a').removeClass('selected');
			$(this).addClass('selected');
			tab=$(this).attr('href');
			if(tab=='#specs'){
				$('#maincontent #leftcol #leftcontentpane #contact').fadeOut();
				$('#maincontent #leftcol #leftcontentpane #imagepane').fadeOut();
				$('#maincontent #leftcol #leftcontentpane #specs').fadeIn();
			}
			if(tab=='#images'){
				$('#maincontent #leftcol #leftcontentpane #contact').fadeOut();
				$('#maincontent #leftcol #leftcontentpane #specs').fadeOut();
				$('#maincontent #leftcol #leftcontentpane #imagepane').fadeIn();
			}
			if(tab=='#contact'){
				$('#maincontent #leftcol #leftcontentpane #specs').fadeOut();
				$('#maincontent #leftcol #leftcontentpane #imagepane').fadeOut();
				$('#maincontent #leftcol #leftcontentpane #contact').fadeIn();
			}
			return false;
		});
		
		// images
		$('#maincontent #leftcol #leftcontentpane #imagepane #thumbsblock a').click(function(){
			imgurl=$(this).attr('href');
			imgstr='<img src="'+imgurl+'" />';
			$('#displaypane').html(imgstr);
			return false;
		});
	
	//send contact form
	$('#bttSubmitContact').click(function(){
		err=0;
		tofill=''
		if($('#frmContact #txtFName').attr('value')==''){ err++;tofill=tofill+'\n- first name'; }
		if($('#frmContact #txtLName').attr('value')==''){ err++;tofill=tofill+'\n- family name'; }
		if($('#frmContact #txtEmail').attr('value')==''){ err++;tofill=tofill+'\n- email'; }
		if($('#frmContact #txtPhone').attr('value')==''){ err++;tofill=tofill+'\n- phone'; }
		if($('#frmContact #txtAnswer').attr('value')==''){ err++;tofill=tofill+'\n- anti-spam answer'; }
		
		if(err>0){
			alert('Please complete the obligatory fields: '+tofill);
			return false;
		}
	
		actionstr=$('#frmContact').attr('action');
		datastr='fname='+$('#frmContact #txtFName').attr('value');
		datastr=datastr+'&lname='+$('#frmContact #txtLName').attr('value');
		datastr=datastr+'&email='+$('#frmContact #txtEmail').attr('value');
		datastr=datastr+'&phone='+$('#frmContact #txtPhone').attr('value');
		datastr=datastr+'&message='+$('#frmContact #txtMessage').attr('value');
		datastr=datastr+'&answer='+$('#frmContact #txtAnswer').attr('value');
		datastr=datastr+'&title='+$('#frmContact #selTitle').attr('value');
		
		$('#frmContact').html('<p class="statusmessage">Sending... please wait...</p>');
		
		
		$.ajax({
			type: "POST",
			url: actionstr,
			data: datastr,
			success: function(html){
				$('#frmContact p.statusmessage').html(html);
			}
		});	
	});
	
	//send node contact form
	$('#bttSubmitNodeContact').click(function(){
		err=0;
		tofill=''
		if($('#frmContact #txtFName').attr('value')==''){ err++;tofill=tofill+'\n- first name'; }
		if($('#frmContact #txtLName').attr('value')==''){ err++;tofill=tofill+'\n- family name'; }
		if($('#frmContact #txtEmail').attr('value')==''){ err++;tofill=tofill+'\n- email'; }
		if($('#frmContact #txtPhone').attr('value')==''){ err++;tofill=tofill+'\n- phone'; }
		if($('#frmContact #txtAnswer').attr('value')==''){ err++;tofill=tofill+'\n- anti-spam answer'; }
		
		if(err>0){
			alert('Please complete the obligatory fields: '+tofill);
			return false;
		}
	
		actionstr=$('#frmContact').attr('action');
		datastr='fname='+$('#frmContact #txtFName').attr('value');
		datastr=datastr+'&lname='+$('#frmContact #txtLName').attr('value');
		datastr=datastr+'&email='+$('#frmContact #txtEmail').attr('value');
		datastr=datastr+'&phone='+$('#frmContact #txtPhone').attr('value');
		datastr=datastr+'&message='+$('#frmContact #txtMessage').attr('value');
		datastr=datastr+'&answer='+$('#frmContact #txtAnswer').attr('value');
		datastr=datastr+'&title='+$('#frmContact #selTitle').attr('value');
		datastr=datastr+'&model='+$('#frmContact #selModel').attr('value');
		
		$('#frmContact').html('<p class="statusmessage">Sending... please wait...</p>');
		
		
		$.ajax({
			type: "POST",
			url: actionstr,
			data: datastr,
			success: function(html){
				$('#frmContact p.statusmessage').html(html);
			}
		});	
	});
	
});
