/***
Alireza Balouch 2010
http://swape.net
***/

var strUrl = "/wp-content/themes/fisk/swapeShop.php" ;
var strStartUrl = '/';

$(document).ready(function(){
   /* swapeShop */
   $('#swapeshop .knapp').click(function(){
   	    var strPris = $('#pris').val() ;
   	    var strNavn = $('#navn').val() ;
   	    var strAntall = $('#antall').val() ;
   	    $.post(strUrl, { 
   	    	navn: strNavn
   	      , pris: strPris
   	      , antall : strAntall
   	      } , function(data){
   	      	$('#sideshop').html(data);
   	      });
   });

$('.storycontent a img').parent().each(function(){
  var mylink= $(this).attr('href');
  if( mylink.search(/jpg/i) != -1){
     $(this).prettyPhoto({ theme : 'light_rounded'  });
  }
});

 $('.endshopantall').live('change' , function(){
   	    var strNavn = $(this).attr('name') ;
   	    var strAntall = $(this).val() ;
   	    $.post(strUrl, { 
   	       n : strNavn
   	      , antall : strAntall
   	      , t : 1
   	      } , function(data){
   	      		showcart();
   	      });
	});
   
   getItNow();
   fadeAnim(); 
});

function lessof(strinput){
	$.post(strUrl, { lessof: strinput } , function(){
		getItNow();
	} );
	
}

function getItNow(){
	$.post(strUrl, { navn: '', pris: '' } , function(data){ $('#sideshop').html(data); });
}


function emptycart(){
	$.post(strUrl, { emptycart: 'doit' } , function(data){ $('#sideshop').html(data); 
	document.location.href = strStartUrl;
	});
}


function fadeAnim(){
    var intImages = $('#innerfade img').length - 1;
    $('#innerfade img:nth(' + intImages+ ')').fadeIn(2000,function(){
        setTimeout('fadeAnim()', 4000);
    });

    $('#innerfade img:nth(0)').fadeOut(1,function(){
        $('#innerfade').append(this);
    });
}

function showcart(){
	$.post(strUrl, { showcart: '1' } , function(data){ $('#content .page').html(data); });
	$('#sideshop').fadeOut(500);
}

function sendItToMeBaby(){
// aha aha
	if( $('#kundenavn').val() != '' && $('#tlf').val() != '' ){
			$.post(strUrl, { 
		  sendit: '1' 
		, k: $('#kundenavn').val()
		, t: $('#tlf').val()
		, e: $('#email').val()
		, c: $('#kommentar').val()
		
		} , function(data){ $('#content .page').html(data); });
	}
	else{
		$.post(strUrl, { showcart: '1' , showerror: '1'} , function(data){ $('#content .page').html(data); });
	}
}

