var nvp_array = new Array;
function nvp_struct(){
		var args = nvp_struct.arguments;
		this.nvp_qvpair = args[0];
		this.nvp_var = args[1];
		this.nvp_value = args[2];
}

function nvp_parse(){
	var querystring = location.search; nvp = querystring.indexOf('&'); searchstring = "true"; prev_nvp = 1; x = 0;
	do {
	if (nvp == -1){nvp = querystring.length; searchstring = "false";}
	var nvp_qvpair = querystring.substring(prev_nvp, nvp); nvp_var = nvp_qvpair.substring(0, nvp_qvpair.indexOf('=')); nvp_value = nvp_qvpair.substring(nvp_qvpair.indexOf('=')+1);
	nvp_array[x] = new nvp_struct(nvp_qvpair,nvp_var,nvp_value); querystring = querystring.substring(nvp + 1,querystring.length);
	if(querystring == null){searchstring = "false"} else {var prev_nvp = 0;		nvp = querystring.indexOf('&');		x++;}
	} while (searchstring == "true")
}

function nvp_get(){
	var args = nvp_get.arguments; nvpsearch = args[0]; nvpvalue = "noval"; nvp_length = nvp_array.length;
	for (var x = 0; x != nvp_length; x++){
		if(nvp_array[x].nvp_var == nvpsearch){nvpvalue = nvp_array[x].nvp_value};
	}
return nvpvalue;
}

function createProductPage(id,image,hasSTD,seq,name,purchaseURL,stdURL, copy){
	arg = createProductPage.arguments;
	this.id = id;
	this.image = image;
	this.hasSTD= hasSTD;
	this.seq = seq;
	this.name = name;
	this.purchaseURL = purchaseURL;
	this.stdURL = stdURL;
	this.copy = copy;
}

product_array = new Array;
product_array[0] = new createProductPage(1,'img/product/std_marquee.jpg',false,1,'Marquee','http://www.etsy.com/view_listing.php?ref=vl_other_2&listing_id=29030050','','Vintage details mix with modern shapes in this save the date that lets a photo of the two of you shine. Add an accent color from your wedding for a personal touch.');
product_array[1] = new createProductPage(2,'img/product/std_boardingpass.jpg',true,2,'Boarding Passes','http://www.etsy.com/view_listing.php?ref=vl_other_2&listing_id=20151822','invitations-detail.html?product=22','Going somewhere? A destination wedding calls for these unique boarding pass save the dates. Choose from a palm tree, modern flower, tropical flower or starfish. Or, we can work together to create a custom graphic.');
product_array[2] = new createProductPage(3,'img/product/std_eventpostcard.jpg',false,3,'Event Postcard','http://www.etsy.com/view_listing.php?ref=vl_other_2&listing_id=20538982','','With or without your photo, these save the date announcements let your personalities take center stage. This design is also available in a poster and ticket format.');
product_array[3] = new createProductPage(4,'img/product/std_eventposter.jpg',false,4,'Event Poster','http://www.etsy.com/view_listing.php?ref=vl_other_2&listing_id=23881123','','A save the date that your guests will want to frame! Includes space for a photo and all your special-day details. This design is also available in a postcard and ticket format.');
product_array[4] = new createProductPage(5,'img/product/std_eventtickets.jpg',false,5,'Event Tickets','http://www.etsy.com/view_listing.php?ref=vl_other_2&listing_id=20925426','','The celebration is one night only—give your guests tickets that double as a special keepsake. This design is also available in a poster and postcard format.');
product_array[5] = new createProductPage(6,'img/product/std_itsadate.jpg',false,6,'It\'s A Date!','http://www.etsy.com/view_listing.php?ref=vl_other_2&listing_id=29029881','','Some guests need more than a subtle hint. Your wedding date becomes the focus of these bold announcements, which opens up to reveal the details of your special day.');
product_array[6] = new createProductPage(7,'img/product/std_moderndots.jpg',true,7,'Modern Dots Postcard','http://www.etsy.com/view_listing.php?ref=vl_other_2&listing_id=21484446','invitations-detail.html?product=8','With a modern interpretation of a calendar on the front, friends and family won’t dare miss your special day. Of course, there’s lots of room on the back for your wedding day details.');
product_array[7] = new createProductPage(8,'img/product/std_gardenparty.jpg',true,8,'Garden Party Postcard','http://www.etsy.com/view_listing.php?ref=vl_other_2&listing_id=20608937','invitations-detail.html?product=4','Spring blooms with hydrangeas and peonies on our elegant announcement. Colors can be customized to match your wedding.');
product_array[8] = new createProductPage(9,'img/product/std_peonies.jpg',false,9,'Peonies',' http://www.etsy.com/view_listing.php?ref=vl_other_2&listing_id=22066349','','Flowers don\'t have to be delicate. These bold blooms add a pop of color to your guests\' mailboxes, and will stand out in their appointment books.');
product_array[9] = new createProductPage(10,'img/product/std_europeanfolk.jpg',false,10,'European Folk',' http://www.etsy.com/view_listing.php?ref=vl_other_2&listing_id=9787772','','These whimsical save the date postcards will have your guests writing your wedding on their calendars in PEN. Two birds work together to hold up a banner with your names and wedding date!');
product_array[10] = new createProductPage(11,'img/product/std_firstclasstravel.jpg',false,11,'First Class Travel',' http://www.etsy.com/view_listing.php?ref=vl_other_2&listing_id=29030195','','Out-of-towners will appreciate this nod to your wedding adventure. A generous detail panel on the back provides room for all the information guests will need.');
product_array[11] = new createProductPage(12,'img/product/std_artdeco.jpg',true,12,'Art Deco','http://www.etsy.com/view_listing.php?ref=vl_other_2&listing_id=29030260','invitations-detail.html?product=10','Step back in time with this striking Art Deco design. Colors can be changed to match your special day, and you’ll definitely want to have one framed as a memento.');
product_array[12] = new createProductPage(13,'img/product/std_peacock.jpg',true,13,'Peacock','http://www.etsy.com/listing/54182800/peacock-save-the-date','invitations-detail.html?product=24','Birds of a feather come together in this sophisticated design. Customize colors to match your wedding and save the date in style with a unique matchbook-style card.');


$(document).ready(function() {
	nvp_parse();
	setProductPage();
	function setProductPage(){
		var prodId = nvp_get('product');
		for(var i = 0; i < product_array.length; i++){
			if(product_array[i].id == prodId){
				//set seq num
				$("#currSeq").html(product_array[i].seq);
				$("#totalSeq").html(product_array.length);
				if(product_array[i].seq != 1){
					$("#prevnext-01").html('<a href="save-date-detail.html?product='+(product_array[i].seq - 1)+'"><span>next</span></a>');
				}
				if(product_array[i].seq != product_array.length){
					$("#prevnext-02").html('<a href="save-date-detail.html?product='+(product_array[i].seq + 1)+'"><span>next</span></a>');
				}
				if(product_array[i].seq == product_array.length){
					$("#prevnext-02").html('<a href="save-date-detail.html?product=1"><span>next</span></a>');
				}
				//set img
				$("#productImg").attr("src", product_array[i].image);
				//Set name
				$("#prodName").html(product_array[i].name);
				//Set copy
				$("#prodCopy").html(product_array[i].copy);
				//shoe matching std
				if(!(product_array[i].hasSTD)){
					$("#matchSTD").hide();
				} else {
					$("#matchSTD").html('<a href="'+product_array[i].stdURL+'">Matching invitation available!</a>');
				}
				$("#quote-02").html('<a href="'+product_array[i].purchaseURL+'" target="win2"><span>Order a Sample</span></a>');
			
			} 
		}
	}
 });
