var clientID = 0;
var postCategory = "";
var editCMS = 0;
var scrolloffset = 0;
var scrollUpEnabled = false;
var scrollDownEnabled = true;
var searchQuery = "";
var servicesId;
var turnOffTheClick = false;
var emailFormOption;
var widgetsArray=new Array();
widgetsArray[2]=new Array("../images/wms1.jpg","Media Player With Geo Blocking","For KT Tunstall's EPK video we created a simple, yet captivating media player, that implements geo-blocking, which checks the country of user in order to display the content in only certain locations.  We also included links back to her website.", '../images/widgetexample1.png', 'replace-swf', 'http://sneakattackmedia.com/geo-blocking/KT_Tunstall/24cksti7hy.swf');
widgetsArray[5]=new Array("../images/wms2.jpg","Countdown Widget","Counting down to the moment The Apples in stereo's album was to be launched into space, we created an embeddable widget that counted down to the day, hour, minute, second.  Once the countdown has reached zero, content can be made available (or it can just flash zero for the rest of time.)", '../images/widgetexample2.png', 'replace-iframe', 'http://sneakattackmedia.com/widgets/applescountdown/embeds.php');
widgetsArray[7]=new Array("../images/wms3.jpg","Image-Comparison Game","Your classic \"find the differences between two images\" puzzle - this one was created for Empire of the Sun.  Users play the game against the clock...all the while, your music is playing.", '../images/widgetexample3.png', 'link-to-minisite', 'http://sneakattackmedia.com/eotsbackup/game.swf');
widgetsArray[9]=new Array("../images/wms4.jpg","Eventful Contest","We partner with Eventful to create tour promo contests, like this one that we did for Terrible Things.  The contest exposes the tour to existing and potential fans on the Evenful network, and allows them to enter to win tickets to shows in their area.", '../images/widgetexample4.png', 'link-to-minisite', 'http://sneakattackmedia.com/contests/terriblethings/');
widgetsArray[3]=new Array("../images/wms5.jpg","Multi-track Media Player","This media player, created for Jukebox the Ghost, can play video or audio, and allows multiple media files to be streamed. Play a full record, stream a series of videos, or make your fans a mix...all in a customized player.", '../images/widgetexample5.png', 'replace-swf', 'http://sneakattackmedia.com/widgets/jtgflashstreamer/test/player.swf');
widgetsArray[6]=new Array("../images/wms6.jpg","User-Generated Content Promotion","Custom-made contest pages, like this one created for Bryan Ferry, show off album art and content, and gather  videos or images uploaded by fans.  The user-generated content is displayed in a gallery, and fans can vote on the best submissions, which furthers promotion on the contest.", '../images/widgetexample6.png', 'link-to-minisite', 'http://youcandancecontest.com/');
widgetsArray[8]=new Array("../images/wms7.jpg","Slider Puzzle Game","Hours (or at least, minutes) of entertainment: a simple slider puzzle featuring your album art, while music from your new album plays.  The time and number of moves the user needed to finish the puzzle is displayed when the image is complete.", '../images/widgetexample7.png', 'replace-iframe', 'http://sneakattackmedia.com/development/slider/embed.php');
widgetsArray[4]=new Array("../images/wms15.jpg","Tweet or Like For Content","Users can unlock exclusive content via a Tweet about the asset or a \"Like\" on Facebook.  This was created for an Ari Hest track.", '../images/widgetexample15.png', 'link-to-minisite', 'http://sneakattackmedia.com/tweettrack/arihesttwitter/');
widgetsArray[13]=new Array("../images/wms9.jpg","Virtual Time Machine","This custom flash application allowed users to travel through time, visiting The Apples in stereo at various points in their career (created for their album <i>Travellers in Space and Time</i>).", '../images/widgetexample9.png', 'link-to-minisite', 'http://sneakattackmedia.com/apples/');
widgetsArray[10]=new Array("../images/wms10.jpg","Digital Scrapbook Widget","This embeddable digital scrapbook was created for Relient K to display photos from the studio and promote their \"win the scrapbook\" contest.  Users can enter to win and also watch at videos, listen to tracks, read their twitter feed and sign up for more the band's mailing list.", '../images/widgetexample10.png', 'replace-swf', 'http://sneakattackmedia.com/widgets/rk/rk3.swf');
widgetsArray[11]=new Array("../images/wms11.jpg","Virtual Tattoo","We used Girl in a Coma's tattoo-inspired logo to create a virtual tattoo for fans to display on their own sites.  The tattoo linked back to the band's website where fans could hear music from their latest album.", '../images/widgetexample11.png', 'replace-iframe', 'http://sneakattackmedia.com/widgets/giac/embed.php');
widgetsArray[12]=new Array("../images/wms12.jpg","E-Card","Users can include their own message when they send a friend a track from their favorite artist.  This example for Laura Jansen also incorporates a contest feature.", '../images/widgetexample12.png', 'link-to-minisite', 'http://sneakattackmedia.com/jansenecard/');
widgetsArray[0]=new Array("../images/wms13.jpg","Image Editing Tool","We created this fun little image-editing tool for The Get Up Kids' album <i>There Are Rules</i>, as the cover art lent itself to the concept.  Fans can upload an image, edit it, and give it overlays. They can then save it to their computer, or share it with friends via Facebook or Twitter.", '../images/widgetexample13.png', 'link-to-minisite', 'http://sneakattackmedia.com/minisites/thegetupkids/');
widgetsArray[1]=new Array("../images/wms14.jpg","Virtual Record Player"," Just hit \"play\"  to throw on some digital records with a virtual turntable, like this one created for The Wilderness of Mantioba.", '../images/widgetexample14.png', 'replace-swf', 'http://sneakattackmedia.com/minisites/womrecordplayer/womplayer.swf');
widgetsArray[14]=new Array("../images/wmsnone.jpg","","", '', 'no-link', '');

/*$(window).ready(function(){
	var frontPageFun=new Array();
	frontPageFun[0]=new Array("images/bgrotate1.jpg","http://www.flickr.com/photos/kodomut/3666796961/","Kodomut", 'http://www.kodomut.com/');
	frontPageFun[1]=new Array("images/bgrotate3.jpg","http://www.flickr.com/photos/kodomut/3667609834/","Kodomut", 'http://www.kodomut.com/');
	frontPageFun[2]=new Array("images/bgrotate2.jpg","http://www.flickr.com/photos/tyreseus/527207577/","Jere Keys", 'http://www.jerekeys.com/');
	
	NumberOfImagesToRotate = 3;
	r = Math.floor(Math.random() * NumberOfImagesToRotate);
	if ($('#frontpage-menu').length > 0){
		$('#background-image').attr('src', frontPageFun[r][0]);
	} else {
		
		$('#background-image').attr('src', '../' + frontPageFun[r][0]);
	}
	$('#imagelink').attr('href', frontPageFun[r][1]);
	$('#imagecreator').html(frontPageFun[r][2]);
	$('#imagecreator').attr('href', frontPageFun[r][3]);
});
*/
$(window).load(function(){

	$('.blogexhibit a').hover(function(){$(this).css('color', '#e11d73')}, function(){$(this).css('color', 'black')});

	if (($(window).width()/$(window).height()) >= 1.6663974152){
		newWidth = $(window).width();
		if ( $('#frontpage-menu').length > 0){
			if (newWidth < 1188){
				newWidth = 1188;
			}
		} else {
			if ( newWidth < 1500){
				newWidth = 1500;
			}
		}
		$('#background-image').css({'width' : newWidth, 'height' : (newWidth*.6000969462)});
		//$('#menu-holder').css({'width' : newWidth});
		
	}
	else if (($(window).width()/$(window).height()) < 1.6663974152){
		newHeight = $(window).height();
		if ( $('#frontpage-menu').length > 0){
			if (newHeight < 550){
				newHeight = 550;
			}
		} else{
			if ( newHeight < 849){
				newHeight = 849;
			}
		}
		$('#background-image').css({'width' : (newHeight*1.6663974152), 'height' : newHeight});
		//$('#menu-holder').css({'width' : $(window).width()});
	}
	
	
	$('.main-menu-button').hover(
		function () {
			$(this).css({'background-color': '#e11d73'});
			$(this).children('p').css({'color' : 'black'});
		}, 
		function () {
			$(this).css({'background-color': 'black'});
			$(this).children('p').css({'color' : 'white'});
		}
	);
	
	$('.services-option').hover(
		function () {
			if ($(this).attr('id') != servicesId){
				$(this).css({'background-color': '#e11d73', 'color' : 'black'});
			}
		}, 
		function () {
			if ($(this).attr('id') != servicesId){
				$(this).css({'background-color': 'black', 'color' : 'white'});
			}
		}
	);
	
	mathWidth = $(window).width();
	if (mathWidth < 950){
		mathWidth = 950;
	}
	mathNewHeight = mathWidth/12.5 + 5;
	mathMarginTop = 390 + (mathWidth/25.94);
	mathFontSize = mathWidth/20.8;
	mathFontSize = mathFontSize + 'pt';
	
	
	if ($('#frontpage-menu').length > 0){
	} else {
		$('#background-holder').css({'min-height' : '789px'});
		$('#menu-holder').css({'min-height' : '900px'});
		//$('#content-holder').css({'height' : ($('#clientpage-menu').position().top - 165)});
	}

	//mathSocialTop = $('#menu-shadow').outerHeight() + $('#menu-shadow').position().top + 10 - (mathWidth/25.94);
	//$('#frontpage-social').css({'top' : mathSocialTop});
	//$('#image-disclaimer').css({'top' : (mathSocialTop + 45)});
	mathShadowBottom = 90 - (mathWidth/24);
	$('#menu-shadow').css({'bottom' : mathShadowBottom});
	
	$('#frontpage-twitter').click(function(){window.open("http://twitter.com/teamsneakattack")});
	$('#frontpage-myspace').click(function(){window.open("http://www.myspace.com/sneakattackmedia")});
	$('#frontpage-facebook').click(function(){window.open("http://www.facebook.com/sneakattackmedia")});
	$('.toggleabout').click(function(){window.location = "http://sneakattackmedia.com/services/"});
	$('.toggleservices').click(function(){window.location = "http://sneakattackmedia.com/about/"});

	
	$('#clients-button').click(function(){window.location = "http://sneakattackmedia.com/clients/"});
	$('#about-button').click(function(){window.location = "http://sneakattackmedia.com/about/"});
	$('#contact-button').click(function(){window.location = "http://sneakattackmedia.com/contact/"});
	$('#news-button').click(function(){window.location = "http://sneakattackmedia.com/news/"});
	$('#newsHeader').click(function(){window.location = "http://sneakattackmedia.com/news/"});
	$('#logo-text-client').click(function(){window.location = "http://sneakattackmedia.com/"});
	$('#logo-ninja-client').click(function(){window.location = "http://sneakattackmedia.com/"});
	
	StartAnimation();
	
	$('.employeeblock').hover(function(){if (emailFormOption != $(this).attr('id')){$(this).animate({'background-color' : '#e11d73'}, 'fast')};}, function(){if (emailFormOption != $(this).attr('id')){$(this).animate({'background-color' : 'white'}, 'fast')};});
	
	$('.clientblock').hover(function(){if (clientID != $(this).attr('id')){$(this).animate({'background-color' : '#e11d73'}, 'fast')};}, function(){if (clientID != $(this).attr('id')){$(this).animate({'background-color' : 'white'}, 'fast')};});
	
	
	$('.employeeblock').click(ShowEmailForm);
	$('#olderposts').click(oldPost);
	$('#newerposts').click(newPost);
	$('.submit-email-link').click(SendEmailForm);
	$('.file-email-link').click(function(){SendEmail();});
	
	$('#newspageoptions').hover(
		function () {
			$(this).css({'color': 'black'});
		}, 
		function () {
			$(this).css({'color': '#cccccc'});
		}
	);
	
	$('.postnews').click(function(){window.location = "http://sneakattackmedia.com/news/"});
	
	$('#newspageselector').change( function(){
		postCategory = $('#newspageselector').val();
		if (postCategory == 'everything'){postCategory = '';};
		dataToLoad = 'postType=' + postCategory;
		$.ajax({
				type: 'post',
				url: '/includes/loopcat.php',
				datatype: 'html',
				data: dataToLoad,
				async: false,
				success: function(data){
					$('#newspagefeed').html(data);
					$('#page-number').html('0');
					$('#olderposts').click(oldPost);
					$('#newerposts').click(newPost);
					window.location.href = '#newsPage=0&postType=' + postCategory;
					
				}
			});
	});
	
	$('.slug').click(slugClick);
	
	$('.services-option').click(function(){
		$('#services-content').scrollTop(0);
		$('#services-content').css({'height' : ($('#content-holder').height() - 140)});
		servicesCarat = $('#' + servicesId).html();
		if (servicesCarat != null){
		servicesCaratRemove =servicesCarat.length - 1;
		servicesCarat = servicesCarat.substring(0,servicesCaratRemove);
		$('#' + servicesId).html(servicesCarat);
		}
		servicesId = $(this).attr('id');
		servicesCarat = $('#' + servicesId).html();
		$('#' + servicesId).html(servicesCarat + '>');
		//alert(servicesId);
		$('.services-selected').attr('class', 'services-option');
		$(this).attr('class', 'services-selected');
		$(this).css('background-color' , '#e11d73');
		$(this).css('color' , 'black');
		
		$('.services-option').css('background-color' , 'black');
		$('.services-option').css('color' , 'white');
		
		$('.services-option').hover(
			function () {
				if ($(this).attr('id') != servicesId){
					$(this).css({'background-color': '#e11d73', 'color' : 'black'});
				}
			}, 
			function () {
				if ($(this).attr('id') != servicesId){
					$(this).css({'background-color': 'black', 'color' : 'white'});
				}
			}
		);
		var servicesContent = new Array("<p class=\"services-starter\">Targeted Marketing</p><p class=\"services-head\">Grassroots Marketing<br/>and Online PR</p><p class=\"services-text\">What does grassroots marketing mean, anyway? To Sneak Attack, it means organically infiltrating the right digital scenes and communities. We use our strong relationships with the tastemakers and gatekeepers in online media to gather candid feedback and interest in what we're working with. Our ever-growing database includes thousands of pop culture, music, entertainment, lifestyle and niche market outlets.</p><p class=\"services-text\" style=\"padding-bottom:10px;margin-bottom:20px;border-bottom: 5px solid black\">Whether you have a new album or book coming out, or your band is going on tour, we'll get the word out to the right people through targeted marketing.</p><a href='http://www.ifc.com/news/2011/02/nicole-atkins-vignettes-from-m.php' target='_blank'><img src='../images/nikatserv.png' class='services-image'/></a><p class=\"services-text\"><br/></p><p class=\"services-text\" style=\"text-align:right\"> < Nicole Atkins - Video Vignette premieres<br/>on IFC.com</p><p class=\"services-text\"><br/></p><a href='http://www.thenewyooxer.yoox.com/eng/index.php/post/5859/katie-melua/' target='_blank'><img src='../images/katmelserv.jpg' class='services-image'/></a><p class=\"services-text\"><br/></p><p class=\"services-text\" style=\"text-align:right\"> < Katie Melua feature on Yoox.com</p><p class=\"services-text\"><br/><br/></p><a href='../images/msnimage.jpg' target='_blank'><img src='../images/cowboyjunkiesmsn.jpg' class='services-image'/></a><p class=\"services-text\"><br/></p><p class=\"services-text\" style=\"text-align:right\"> < Cowboy Junkies - Featured Listening Booth<br/>on MSN</p><p class=\"services-text\"><br/></p><p class=\"services-head\">Strategic Marketing</p><p class=\"services-text\" style=\"padding-bottom:10px;margin-bottom:20px;border-bottom: 5px solid black\">We'll develop and implement creative contests, promotions, fan-based initiatives, and user-generated content efforts.  Sneak Attack looks at the overall project, creates the concepts and then launches them into action so we can engage your current fans and generate news ones for you, as well.</p><a href='http://www.dailycandy.com/chicago/article/89814/Chicago-Events-and-Diversions?utm_source=dailycandychi&utm_medium=rss' target='_blank'><img src='../images/juketghoserv.jpg' class='services-image'/></a><p class=\"services-text\"><br/></p><p class=\"services-text\" style=\"text-align:right\"> < Jukebox the Ghost contest on Daily Candy</p><p class=\"services-text\"><br/><br/></p> <a href ='http://youcandancecontest.com/' target='_blank'><img src='../images/bryferserv.jpg' class='services-image'/></a><p class=\"services-text\"><br/></p><p class=\"services-text\" style=\"text-align:right\"> < Bryan Ferry \"You Can Dance\"video contest</p><p class=\"services-text\"><br/><br/></p><a href='http://sneakattackmedia.com/contests/terriblethings/' target='_blank'><img src='../images/terrthingsserv.jpg' class='services-image'/></a><p class=\"services-text\"><br/></p><p class=\"services-text\" style=\"text-align:right\"> < Terrible Things eventful contest</p><p class=\"services-text\"><br/><br/></p><a href='http://www.animalsoffission.com/' targets='_blank'><img src='../images/filmschserv.jpg' class='services-image'/></a><p class=\"services-text\"><br/></p><p class=\"services-text\" style=\"text-align:right\"> < Film School Animals of Fission<br/>design contest</p><p class=\"services-text\"><br/><br/></p><p class=\"services-head\">Content Seeding</p><p class=\"services-text\">Most likely, you already have some content that shows off who you are. Whether it's a video, stream, download, game or other asset, you want the digital world to see it, and we can help.</p><p class=\"services-text\"  style=\"padding-bottom:10px;margin-bottom:20px;border-bottom: 5px solid black\">Sneak Attack will push each campaign's digital content into the wild through grassroots strategy, well-crafted reach outs, and our own Sneak-E-Team, who will seed the content out across the web to the right destinations.</p><a href='http://www.myoldkentuckyblog.com/?p=13968' target='_blank'><img src='../images/otrserv.jpg' class='services-image'/></a><p class=\"services-text\"><br/></p><p class=\"services-text\" style=\"text-align:right\"> < Over the Rhine - \"The King Knows How\"<br/>on My Old Kentucky Blog</p><p class=\"services-text\"><br/></p><a href='http://stereogum.com/366361/against-me-i-was-a-teenage-anarchist-vide/news/' target='_blank'><img src='../images/againstmeserv.jpg' class='services-image'/></a><p class=\"services-text\"><br/></p><p class=\"services-text\" style=\"text-align:right\"> < Against Me!' - \"I Was a Teenage Anarchist\" video on Stereogum</p><p class=\"services-text\"><br/></p><a href='http://pitchfork.com/forkcast/13771-the-last-drop/' target='_blank'><img src='../images/joyforserv.jpg' class='services-image'/></a><p class=\"services-text\"><br/></p><p class=\"services-text\" style=\"text-align:right\"> < The Joy Formidable - \"The Last Drop\" on Pitchfork</p>", "<p class=\"services-starter\">Social Media Optimization</p><p class=\"services-text\">With so many options for social media available, Sneak Attack aims to focus on the platforms that make the most sense for each client. We develop the social media properties you need, build a community of supporters and then engage them, increasing your network even more.</p><p class=\"services-text\">At the start of the campaign, we'll make sure that your image is consistent, conspicuous and eye-catching across all of your online properties. We'll provide the design and functionality, and expand your fan base by providing content, incentivizing your supporters, always giving them a reason to come back.</p><p class=\"services-text\"  style=\"padding-bottom:10px;margin-bottom:20px;border-bottom: 5px solid black\">We'll also take it a step further, teaching you best practices for platforms like Twitter and Facebook so you can be sure to keep people interested.</p><a  href='http://www.facebook.com/onlysonmusic' target='_blank'><img src='../images/onlysonfacebook.jpg' class='services-image'/></a><p class=\"services-text\"><br/><br/></p><p class=\"services-text\" style=\"text-align:right\"> < Only Son Facebook Page</p><p class=\"services-text\"><br/></p><a  href='http://www.listn.to/saadi' target='_blank'><img src='../images/saadifacebook.jpg' class='services-image'/></a><p class=\"services-text\"><br/><br/></p><p class=\"services-text\" style=\"text-align:right\"> < Saadi Facebook Page (with video)</p><p class=\"services-text\"><br/></p><a  href='http://www.myspace.com/fuzzelectro' target='_blank'><img src='../images/fuzzmyspace.jpg' class='services-image'/></a><p class=\"services-text\"><br/><br/></p><p class=\"services-text\" style=\"text-align:right\"> < FuzZ MySpace Page</p>","<p class=\"services-starter\">Online Advertising</p><p class=\"services-text\">There are a lot of places to book ads online. What sites make sense for you and your campaign? How much should you spend? What's the difference between CPM and CPC?  Should you use a banner ad or a rich media ad?</p><p class=\"services-text\">We can help you navigate the online ad world, propose what's best for your campaign, book the ads, and build the creative elements for you, too.</p><p class=\"services-text\"  style=\"padding-bottom:10px;margin-bottom:20px;border-bottom: 5px solid black\">You can expect a full report of ROI, click-through rates and metrics at the end of the campaign.</p><a href='http://sneakattackmedia.com/otr/jim.html' target='_blank'><img src='../images/otrbannerserv.jpg' class='services-image'/></a><p class=\"services-text\"><br/></p><p class=\"services-text\" style=\"text-align:right\"> < Over the Rhine banner ads</p>", "<p class=\"services-starter\">Brand Partnerships</p><p class=\"services-text\">We're constantly making new relationships here at Sneak Attack, and we've executed some wonderful creative ideas for alliances between our clients and relevant brands.</p><p class=\"services-text\"  style=\"padding-bottom:10px;margin-bottom:20px;border-bottom: 5px solid black\">Let us find you the right partnership that could bring you a whole new network of fans.</p><a href='http://www.stevemadden.com/music/default.aspx?artist_id=31' target='_blank'><img src='../images/cassettekidssm.jpg' class='services-image'/></a><p class=\"services-text\"><br/><br/></p><p class=\"services-text\" style=\"text-align:right\"> < Cassette Kids on SteveMaddenMusic.com</p><p class=\"services-text\"><br/></p><a href='http://www.smashbox.com/ToriAmos' target='_blank'><img src='../images/toriamosservices.jpg' class='services-image'/></a><p class=\"services-text\"><br/><br/></p><p class=\"services-text\" style=\"text-align:right\"> < Tori Amos Smashbox promotion</p>", "<div id=\"widget-holder\">" );

	if (servicesId == "social-networking"){
		$('#services-content').css('overflow-y', 'scroll').css('margin-top', '90px').html(servicesContent[1]);
	} else if (servicesId == "online-advertising"){
		$('#services-content').css('overflow-y', 'scroll').css('margin-top', '90px').html(servicesContent[2]);
	} else if (servicesId == "targeted-marketing"){
		$('#services-content').css('overflow-y', 'scroll').css('margin-top', '90px').html(servicesContent[0]);
	} else if (servicesId == "brand-partnerships"){
		$('#services-content').css('overflow-y', 'scroll').css('margin-top', '90px').html(servicesContent[3]);
	} else if (servicesId == "widgets-and-minisites"){
		widgetIterator = 0;
		widgetHTML = servicesContent[4];
		$('#services-content').css('overflow-y', 'visible').css('margin-top', '110px');
		while (widgetIterator < 15) {
			widgetHTML = widgetHTML + "<img id='widget" + (widgetIterator + 1) + "' class='widget-thumb' src='" + widgetsArray[widgetIterator][0] + "'/>";
			if ( widgetIterator == 14){
				widgetHTML = widgetHTML + "</div>";
			}
			widgetIterator++;		}
		$('#services-content').html(widgetHTML);
		$('.widget-thumb').click(function(){
			widgetSelection = (($(this).attr('id').substr(6)) - 1);
			if (widgetSelection == 14){
				widgetSelection = 0;
			}
			newHeight = $(window).height();
			if ( newHeight < 849){
				newHeight = 849;
			}
			$('#widget-overlay').slideDown(800, function(){$('#widget-overlay').height(newHeight)});
			imageHTML = '<img src="' + widgetsArray[widgetSelection][3] + '" id="' + widgetsArray[widgetSelection][4] + '"/>';
			$('#widget-image').html(imageHTML);
			$('#widget-name').html(widgetsArray[widgetSelection][1]);
			$('#widget-descrip').html(widgetsArray[widgetSelection][2]);
			$('#close-widgets').click(function(){
				$('#widget-overlay').slideUp(800);
				turnOffTheClick = true;
			});
			if (turnOffTheClick == false){
			$('#widget-scroll-prev').click(function(){
				widgetSelection = widgetSelection - 1;
				if ( widgetSelection < 0){
					widgetSelection = 13;
				}
				imageHTML = '<img src="' + widgetsArray[widgetSelection][3] + '" id="' + widgetsArray[widgetSelection][4] + '"/>';
				$('#widget-image').animate({'opacity' : 0}, 300, function(){$('#widget-image').html(imageHTML);}).delay(400).animate({'opacity' : 1}, 300);
				$('#widget-name').animate({'opacity' : 0}, 300, function(){$('#widget-name').html(widgetsArray[widgetSelection][1]);}).delay(400).animate({'opacity' : 1}, 300);
				$('#widget-descrip').animate({'opacity' : 0}, 300, function(){$('#widget-descrip').html(widgetsArray[widgetSelection][2]);}).delay(400).animate({'opacity' : 1}, 300);
			});
			$('#widget-scroll-next').click(function(){
				widgetSelection = widgetSelection + 1;
				if ( widgetSelection > 13){
					widgetSelection = 0;
				}
				imageHTML = '<img src="' + widgetsArray[widgetSelection][3] + '" id="' + widgetsArray[widgetSelection][4] + '"/>';
				$('#widget-image').animate({'opacity' : 0}, 300, function(){$('#widget-image').html(imageHTML);}).delay(400).animate({'opacity' : 1}, 300);
				$('#widget-name').animate({'opacity' : 0}, 300, function(){$('#widget-name').html(widgetsArray[widgetSelection][1]);}).delay(400).animate({'opacity' : 1}, 300);
				$('#widget-descrip').animate({'opacity' : 0}, 300, function(){$('#widget-descrip').html(widgetsArray[widgetSelection][2]);}).delay(400).animate({'opacity' : 1}, 300);
			});
			$('#widget-image').click(function(){
				widgetImageChild = $('#widget-image').children();
				if ( $(widgetImageChild[0]).attr('id') == 'replace-swf'){
					swfHTML = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" width="500" height="292" id="player" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="allowFullScreen" value="false" /><param name="movie" value="'+ widgetsArray[widgetSelection][5] + '" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />	<embed src="'+ widgetsArray[widgetSelection][5] + '" quality="high" bgcolor="#ffffff" width="500" height="292" name="player" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" /></object>';
					$('#widget-image').html(swfHTML);
				} else if ( $(widgetImageChild[0]).attr('id') == 'replace-iframe'){
					iframeHTML = '<iframe src="' + widgetsArray[widgetSelection][5] + '" width="500" height="292"></iframe>';
					$('#widget-image').html(iframeHTML);
				} else if ( $(widgetImageChild[0]).attr('id') == 'link-to-minisite'){
					window.open(widgetsArray[widgetSelection][5]);
				}
			});
			}
		});
	}
	});
	
	if ($('#isCMS').length > 0)
	{	
	editCMS = 1;
		$('.deletebutton').click(function() {clientID = $(this).parent().attr('id'); DeleteClient()});
		
		$('#addnew').hover(function(){$(this).css('background-color', '#e11d73').css('color', 'black')}, function(){$(this).css('background-color', 'black').css('color', 'white')});
		$('.uploadbutton').click(function(){UploadThings()});	
		$('#addnew').click(function() {AddNewClient()});
		$('.employeeblock').click(function(){
			ShowContactForm();
		});
		$('.clientblock').click(function() {
			if (clientID == $(this).attr('id')){CloseContainer();
			$('.clientblock').css({'background-color' : 'white', 'color' : 'black'});
			} 
			
	 		else { clientID = $(this).attr('id'); ExpandSidebar();
	 		$(this).siblings().css({'background-color' : 'white', 'color' : 'black'});

	 		}});
			$('.uploadbutton').click(function(){UploadThings()});
	}
	else 
	{
		if ($('#clientssidebar').length > 0)
	{
		$('.clientblock').click(function() {
			if (clientID == $(this).attr('id')){CloseContainer();} 
	 		else { clientID = $(this).attr('id'); ExpandSidebar();
	 		$(this).siblings().css({'background-color' : 'white', 'color' : 'black'});
			};
	});
	};
	};
	dataToLoad = 'loadSidebar=yes&isCMS=' + editCMS;
		$.ajax({
				type: 'post',
				url: '../clients/controller.php',
				datatype: 'html',
				data: dataToLoad,
				async: false,
				success: function(data){
					$('.sidebarholder').html(data);
					reExpand();
				}
			});
	if ($("#clientscontainer").length > 0){
TruncateSideBar();
TruncateMainName();
if (editCMS == 1){
	$("#scrolldown").click(function(){SidebarScrollDown(10, false);});
	$("#scrollup").click(function(){SidebarScrollUp(10, false);});
	$('#clientsearch').click(function(){SearchClients(10, false)});
	}
else {
	$('#clientsearch').click(function(){SearchClients(10, false)});
	$('#scrollpast').click(function(){SidebarScrollPast()});
	}
};

});

$(window).resize(function() {
	if (($(window).width()/$(window).height()) >= 1.6663974152){
		newWidth = $(window).width();
		if ( $('#frontpage-menu').length > 0){
			if (newWidth < 1188){
				newWidth = 1188;
			}
		} else {
			if ( newWidth < 1500){
				newWidth = 1500;
			}
		}
		$('#background-image').css({'width' : newWidth, 'height' : (newWidth*.6000969462)});
		//$('#menu-holder').css({'width' : newWidth});
		
	}
	else if (($(window).width()/$(window).height()) < 1.6663974152){
		newHeight = $(window).height();
		if ( $('#frontpage-menu').length > 0){
			if (newHeight < 550){
				newHeight = 550;
			}
		} else{
			if ( newHeight < 849){
				newHeight = 849;
			}
		}
		$('#background-image').css({'width' : (newHeight*1.6663974152), 'height' : newHeight});
		//$('#menu-holder').css({'width' : $(window).width()});
	}
	mathWidth = $(window).width();
	if (mathWidth < 950){
		mathWidth = 950;
	}
	mathNewHeight = mathWidth/12.5 + 5;
	mathMarginTop = 390 + (mathWidth/25.94);
	mathFontSize = mathWidth/20.8;
	mathFontSize = mathFontSize + 'pt';
	
	if ($('#frontpage-menu').length > 0){
	} else {
		newMarginShadow = -((($(window).width()*.974)/2) + 20);
			if (newMarginShadow > -480){
				newMarginShadow = -480;
			}
			newContentHeight = ($(window).height() - 235);
			if (newContentHeight < 554){
				newContentHeight = 554;
			}
		$('#content-holder').css({'height' : newContentHeight});
		$('#services-content').css({'height' : ($('#content-holder').height() - 140)});
		$('#content-shadow').css({'top' : 140, 'height' : ($('#clientpage-menu').position().top - 165), 'margin-left' : newMarginShadow});
	}
	
	$('.main-menu-button').hover(
		function () {
			$(this).css({'background-color': '#e11d73', 'color' : 'black'});
		}, 
		function () {
			$(this).css({'background-color': 'black', 'color' : 'white'});
		}
	);
	//mathSocialTop = $('#menu-shadow').outerHeight() + $('#menu-shadow').position().top + 10 - (mathWidth/25.94);
	//$('#frontpage-social').css({'top' : mathSocialTop});
	//$('#image-disclaimer').css({'top' : (mathSocialTop + 45)});
	
	mathShadowBottom = 90 - (mathWidth/24);
	$('#menu-shadow').css({'bottom' : mathShadowBottom});
	newHeight = $(window).height();
	if ( newHeight < 849){
		newHeight = 849;
	}
	$('#widget-overlay').height(newHeight);
	//$('#menu-holder div div p').css('margin-top', '18px');
	
	//$('#clientpage-menu div p').css('margin-top', '18px');
});

function StartAnimation(){

	$('#background-image').animate({'opacity' : 1}, 500, function(){
		if ( $('#clientpage-menu').length > 0){
		newMarginShadow = -((($(window).width()*.974)/2) + 20);
			if (newMarginShadow > -480){
				newMarginShadow = -480;
			}
			newContentHeight = ($(window).height() - 235);
			if (newContentHeight < 554){
				newContentHeight = 554;
			}
			$('#content-holder').animate({'height' : newContentHeight}, 200, function(){if ($('#twittercontent').length > 0){$('#twittercontent').fadeIn(300);setNews();};});
			$('#services-content').css({'height' : ($('#content-holder').height() - 140)});
			
		}
	
	});
	
	
};

function LoadTwitters(){
var html = '';
$.ajax({
	url: "http://twitter.com/statuses/user_timeline/teamsneakattack.json?count=7&callback=?",
	dataType: 'json',
	success: function(data) {
	
		
		$.each(data, function (i, item) {
			var parseTwitter = item.text;
			var exp = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim;
			parseTwitter = parseTwitter.replace(exp,"<a href='$1'>$1</a>");
			var exp = /(@(\b[A-Za-z0-9_]*\b)?)/gim;
			parseTwitter = parseTwitter.replace(exp,"@<a href=\"http://www.twitter.com/$1\" target=\"twitterwindow\" >$1</a>");
			parseTwitter = parseTwitter.replace(/>@/gim, '>');
			var exp = /(#(\b[A-Za-z0-9_]*\b)?)/gim;
			parseTwitter = parseTwitter.replace(exp,"<a href=\"http://twitter.com/search?q=%23$1\" target=\"twitterwindow\" >$1</a>");
			parseTwitter = parseTwitter.replace(/http:\/\/twitter.com\/search?q=%23#/gim, 'http://twitter.com/search?q=%23');
			html += "<div class=\"sneak-tweet\"><p>" + parseTwitter + "</p><div class=\"tweet-date\">Posted on <a href=\"http://twitter.com/#!/teamsneakattack/status/" + item.id_str + "\">" + item.created_at.substr(0,11) +  item.created_at.substr(26) + "</a> at <a href=\"http://twitter.com/#!/teamsneakattack/status/" + item.id_str + "\">" + item.created_at.substr(12,7) + "</a></div></div>";
			$('#twitter-feed').html(html);
	});
	}}); 
	

};

function ShowEmailForm() {
	if (emailFormOption == $(this).attr('id')){
	$('.contact-email-holder').slideUp(800); emailFormOption = "" ;}
	else {
	emailFormOption = $(this).attr('id');
	emailFormOpen = "#" + emailFormOption + "-email";
	$('.contact-email-holder').slideUp(800, function(){setTimeout("$(emailFormOpen).slideDown(800);", 1200);});}
};

function SendEmailForm() {
	emailFormOption = $(this).attr('id');
	emailFormHolder = "#" + $(this).attr('id') + "-email";
	emailFormName = "#" + emailFormOption + "-email-form input[name=name]";
	emailFormEmail = "#" + emailFormOption + "-email-form input[name=email]";
	emailFormMessage = "#" + emailFormOption + "-email-form textarea[name=message]";
	emailFormEmail = $(emailFormEmail).val();
	emailFormName = $(emailFormName).val();
	emailFormMessage = $(emailFormMessage).val();
	
	if (emailFormName.length > 0 && emailFormMessage.length > 0 && checkMail(emailFormEmail) == true){
	
	dataToLoad = "emailtoname=" + emailFormOption + "&emailfromname=" + emailFormName + "&emailaddy=" + emailFormEmail + "&emailmessage=" + emailFormMessage;
	
	$.ajax({
	type: 'post',
	url: ('sendemail.php'),
	datatype: 'html',
	data: dataToLoad,
	success: function(html){
		$(emailFormHolder).html(html);
	},
	error: function() {
	alert('An error occured! 1083');
	}});
	
	}
	else if (emailFormName.length == 0 || emailFormMessage.length == 0 || emailFormEmail.length == 0){
		alert('You haven\'t filled out all fields. Please make sure all fields are complete before sending email.');
	}
	else if (checkMail(emailFormEmail) == false){
		alert('The email address you entered is invalid. Make sure it is entered fully and correctly.');
	};
};

function checkMail(email){
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(email)) {
		return true;
	}
	return false;
};

function SendEmail(){
	var subFilename = "";
	subName = $('#name-file-option').val();
	subEmail = $('#email-file-option').val();
	subMessage = $('.text-file-email').val();
	
		if (subName.length > 0){ 
			if(subEmail.length > 0){
				if (subMessage.length > 0){
						if ( checkMail(subEmail) == true){
							$('#file-form').submit();
						}
						else {
							alert('You haven\'t submitted a valid email address.');
						}; 
			
				}
				else {
					alert('You haven\'t completed the submission form! Please add the title of your design, and make sure you\'ve.attached either a file or url.');
				};
			 
			}
			else {
				alert('You haven\'t completed the submission form! Please add your email address, and any other fields still empty.');
			};
	
		}
		else {
			alert('You haven\'t completed the submission form! Please add your name, and any other fields still empty.');
		};
};

function ExpandSidebar() {
	
	var alreadyClicked = true;

		$('div#' + clientID).css('background-color', '#e11d73').css('color','white');
	if (alreadyClicked = false) {$(this).click(function() {CloseContainer()});	
	};
	dataToLoad = 'clientID=' + clientID + '&loadclient=yes&isCMS=' + editCMS;	
	$.ajax({
	type: 'post',
	url: '/clients/controller.php',
	datatype: 'html',
	data: dataToLoad,
	async: false,
	success: function(html){
	
		///var blurbs = $('.blurb');
		$('#clientscontainer').html(html);
		
		$('#editbutton').click(function() {EditEverything()});
		},
	error: function() {
	alert('An error occured! 222');
	}
	});
	$('#clientscontainer').show();
	TruncateMainName();
	$('#content-holder').scrollTop(0);
};	

function SidebarScrollDown(scrolllim, featuredscroll){

	if (scrollDownEnabled == true){
		
		scrollUpEnabled = false; scrollDownEnabled = false;
		scrolloffset = scrolloffset + scrolllim;
		scrollmargin = 0 - (scrolllim * 100);
		$('.scrollbutton').animate({
			opacity : '.3'
			},
			300,
			function(){
				$('.sidebarholder').animate({
					opacity : '0'
				},
				100,
				function(){$('#sidebarload').fadeIn(100);}
				).delay(1000).animate({
					'margin-top' : '0'
				},
				1,
				function(){
					
					dataToLoad = 'scrolloffset=' + scrolloffset + '&isCMS=' + editCMS + '&loadSidebar=yes&searchquery=' + searchQuery;
					$.ajax({
					type: 'post',
					url: '/clients/controller.php',
					datatype: 'html',
					data: dataToLoad,
					async: false,
					success: function(html){
					
				$('#sidebarload').fadeOut(1, function(){
						$('.sidebarholder').html(html);
						$('.sidebarholder').animate({
					opacity : '1'
				},
				100,
				function(){if (featuredscroll == true){
							$(".draggable.featuredblock").draggable({ revert: 'invalid', start: function(){ featuredclientID = $(this).attr("id"); /*alert(featuredclientID);*/}});
						}
						else {
							reExpand();
						};
						TruncateSideBar();
						}
						);});
						SideBarArray = $(".sidebarholder").children();
						if (SideBarArray.length < scrolllim){
							$('#scrollup').animate({opacity : '1'}, 300);
							scrollUpEnabled = true;
						}
						else {
							$('.scrollbutton').animate({opacity : '1'}, 300);
							scrollUpEnabled = true;
							scrollDownEnabled = true;
							};
						
						;
					}
					})
				}
				)
			}
		)
	};
	
}

function SidebarScrollUp(scrolllim, featuredscroll){
	if (scrollUpEnabled == true){
		scrollUpEnabled = false; scrollDownEnabled = false;
		scrolloffset = scrolloffset - scrolllim;
		scrollmargin = (scrolllim * 100) + 40;
		$('.scrollbutton').animate({
			opacity : '.3'
			},
			300,
			function(){
				$('.sidebarholder').animate({
					opacity : '0'
				},
				100,
				function(){$('#sidebarload').fadeIn(100);}
				).delay(1000).animate({
					'margin-top' : '0'
				},
				1,
				function(){
					if (featuredscroll == true){
					$('#featuredclientssidebar').css('overflow-y', 'visible');
					dataToLoad = 'scrolloffset=' + scrolloffset + '&featuredscroll=' + featuredscroll + '&searchquery=' + searchQuery;
					}
					else{
					dataToLoad = 'scrolloffset=' + scrolloffset + '&isCMS=' + editCMS + '&loadSidebar=yes&searchquery=' + searchQuery;
					};
					$.ajax({
					type: 'post',
					url: '/clients/controller.php',
					datatype: 'html',
					data: dataToLoad,
					async: false,
					success: function(html){
					$('#sidebarload').fadeOut(1, function(){
						$('.sidebarholder').html(html);
						
						$('.sidebarholder').animate({
					opacity : '1'
				},
				100,
				function(){if (featuredscroll == true){
							$(".draggable.featuredblock").draggable({ revert: 'invalid', start: function(){ featuredclientID = $(this).attr("id"); /*alert(featuredclientID);*/}});
						}
						else {
							reExpand();
						};
						TruncateSideBar();
						}
						);});
						if (scrolloffset == 0){
							$('#scrolldown').animate({opacity : '1'}, 300);
							scrollDownEnabled = true;
						}
						else {
							$('.scrollbutton').animate({opacity : '1'}, 300);
							scrollUpEnabled = true;
							scrollDownEnabled = true;
							};
						
					}
					})
				}
				)
			}
		)
	};
	
}

function SidebarScrollPast(){

		var scrollTo = $('#pastClientsHead').position().top;
		$('#content-holder').scrollTop(scrollTo);
}

function SearchClients(scrolllim, featuredscroll){
searchQuery = $('#clientinput').val();
scrolloffset = 0;

				$('.sidebarholder').animate({
					opacity : '0'
				},
				100,
				function(){$('#sidebarload').fadeIn(100);}
				).delay(1000).animate({
					'margin-top' : '0'
				},
				1,
				function(){
					if (featuredscroll == true){
					$('#featuredclientssidebar').css('overflow-y', 'visible');
					dataToLoad = 'scrolloffset=0&featuredscroll=' + featuredscroll + '&searchquery=' + searchQuery;
					}
					else{
					dataToLoad = 'scrolloffset=0&isCMS=' + editCMS + '&loadSidebar=yes&searchquery=' + searchQuery;
					};
					$.ajax({
					type: 'post',
					url: '/clients/controller.php',
					datatype: 'html',
					data: dataToLoad,
					async: false,
					success: function(html){
					
				$('#sidebarload').fadeOut(1, function(){
						$('.sidebarholder').html(html);
						$('.sidebarholder').animate({
					opacity : '1'
				},
				100,
				function(){
							reExpand();
							TruncateSideBar();
						}
						);});
						SideBarArray = $(".sidebarholder").children();
						if (SideBarArray.length < scrolllim){
							$('#scrollup').animate({opacity : '1'}, 300);
							scrollUpEnabled = true;
						}
						else {
							$('.scrollbutton').animate({opacity : '1'}, 300);
							scrollUpEnabled = true;
							scrollDownEnabled = true;
							};
						
						;
					}
					})
				}
				)
	
}

function TruncateSideBar(){
	//$('.title').each(function(index) {
	 //if($(this).html().length > 25){$(this).css('font-size', '15pt')};	});
	
}

function TruncateMainName(){
	if($('#descriptiontitle').html().length > 16){$('#descriptiontitle').css('font-size', '22pt').css('top', '97px')};
	if($('#descriptiontitle').html().length > 25){$('#descriptiontitle').css('font-size', '15pt').css('top', '107px')};
	if($('#descriptionsubtitle').html().length > 20){$('#descriptionsubtitle').css('font-size', '18pt').css('top', '130px')};
	if($('#descriptionsubtitle').html().length > 30){$('#descriptionsubtitle').css('font-size', '12pt').css('top', '140px')};
}

function reExpand() {

	if ($('#isCMS').length > 0){

	$('.deletebutton').click(function() {clientID = $(this).parent().attr('id'); DeleteClient()});
		
		$('#addnew').hover(function(){$(this).css('background-color', '#e11d73').css('color', 'black')}, function(){$(this).css('background-color', 'black').css('color', 'white')});
		$('.uploadbutton').click(function(){UploadThings()});	
		};
		
		$('.clientblock').click(function() {
			if (clientID == $(this).attr('id')){CloseContainer();} 
			
	 		else { clientID = $(this).attr('id'); ExpandSidebar();
	 		if ($('#isCMS').length > 0){
	 		$(this).siblings().children('.deletebutton').css({'margin-left' : '0px', 'background-image' : ''});};
	 		$(this).siblings().css({'background-image' : '', 'background-color' : '#white', 'color' : 'black'});	
	 		}});
	 	$('.clientblock').hover(function(){if (clientID != $(this).attr('id')){$(this).animate({'background-color' : '#e11d73'}, 'fast')};}, function(){if (clientID != $(this).attr('id')){$(this).animate({'background-color' : 'white'}, 'fast')};});
}

function CloseContainer() {
	$('div#' + clientID).css('background-color', 'white').css('color','black');
	$('#clientscontainer').fadeOut(400);
	$('div#' + clientID).css('background-image', '');
};

function AddNewClient() {

dataToLoad = 'addClient=yes';

	$.ajax({
	type: 'post',	
	url: '/clients/controller.php',
	datatype: 'html',
	data: dataToLoad,
	//target: ('#clientssidebar'),
	async: false,
	success: function(html){
		$.ajax({
	type: 'post',
	url: '/clients/controller.php',
	datatype: 'html',
	data: 'isCMS=1&loadSidebar=yes',
	success: function(html) {
	$('.sidebarholder').html(html);
	reInitialize();
		},
	error: function() {
	alert('error');
	}
	}
	);

		},
	error: function() {
	alert('An error occured! 472');
	}
	});

};

function DeleteClient(){
$('div#' + clientID).css('background-image', 'url(/images/deleteclient.png)');

	var yes = confirm("Whoa there chief! Do you really want to DELETE client?");

	if (yes == 1) {
	dataToLoad = 'clientID=' + clientID + '&deleteClient=yes',

	$.ajax({
	type: 'post',
	url: '/clients/controller.php',
	datatype: 'html',
	data: dataToLoad,
	success: function(html) {
	alert('Client' + clientID + ' should have been deleted from the database.');
	$.ajax({
	type: 'post',
	url: '/clients/controller.php',
	datatype: 'html',
	data: 'isCMS=1&loadSidebar=yes',
	success: function(html) {
	$('.sidebarholder').html(html);
	reInitialize();
		},
	error: function() {
	alert('error');
	}
	}
	);
		},
	error: function() {
	alert('error');
	}
	}
	);
	};
	};

function reInitialize() {
		
		dataToLoad = 'clientID=' + clientID + '&loadclient=yes&isCMS=' + editCMS ;	
	$.ajax({
	type: 'post',
	url: '/clients/controller.php',
	datatype: 'html',
	data: dataToLoad,
	async: false,
	success: function(html){
		if (editCMS == 1){}
		$('#editbutton').click(function() {EditEverything()});
		$('.clientblock').click(function() {clientID = $(this).attr('id'); ExpandSidebar()});
		$('#clientscontainer').html(html);
		$('.deletebutton').click(function() {clientID = $(this).parent().attr('id'); DeleteClient()});
$('.clientblock').hover(function(){if (clientID != $(this).attr('id')){$(this).animate({'background-color' : '#e11d73'}, 'fast')};}, function(){if (clientID != $(this).attr('id')){$(this).animate({'background-color' : 'white'}, 'fast')};});
	},
	error: function() {
	alert('An error occured! Function ReInitialize');
	}
	});

};

function EditEverything() {
	$('#content-holder').scrollTop(0);
	
	$('#editbutton').replaceWith('<p id="save">Save</p>');
	descriptionTitle = $('#descriptiontitle').html();
	descriptionSubTitle = $('#descriptionsubtitle').html();
	descriptionLabel = $('#descriptionlabel').html();
	description = $('#description').html();
	linkedids = $('.pastidreadout').html();
	//blurb = $('#blurb').html();
	releaseDate = $('#rdate').html();
	dataToLoad = 'clientID=' + clientID + '&editDownloads=yes&editDownload=1&isCMS=1';

	$.ajax({
	type: 'post',	
	url: '/clients/controller.php',
	datatype: 'html',
	data: dataToLoad,
	async: false,
	success: function(html){

	var replaceHTML = "<div id=clientscontainer>" + html + "</div>"
	$('#clientscontainer').replaceWith(replaceHTML);
	$('#descriptiontitle').replaceWith('<input type="text" id="descriptiontitle" value="' + descriptionTitle + '" />');
	$('#descriptionsubtitle').replaceWith('<input type="text" id="descriptionsubtitle" value="' + descriptionSubTitle + '" />');
	$('#descriptionlabel').replaceWith('<input type="text" id="descriptionlabel" value="' + descriptionLabel + '" />');
	$('#description').replaceWith('<textarea id="description" >' + description + '</textarea>');
	$('.pastidreadout').replaceWith('<textarea class="pastidreadout" >' + linkedids + '</textarea>');
	
	///$('#blurb').replaceWith('<textarea id="blurb" rows="2" cols="59">' + blurb + '</textarea>');
	$('#rdate').replaceWith('<input type="text" id="rdate" value="' + releaseDate + '" />');
	$('#uploadbutton').css('display','block');
	$('#uploadbutton').click(function() {UploadThings()});
	$('#editbutton').replaceWith('<p id="save">Save</p>');
	$('#save').click(function() {UpdateClientTitle()});
	$('#newdownload').click(function() {AddNewDownload()});
	$('#newlink').click(function() {AddNewLink()});
	$('#newmiscclick').click(function() {AddNewMisc()});
	$('#newphoto').click(function() {AddNewPhoto()});
	$('.removelink').click(function() { DeleteDownloadLink(this)});
	$('.removelinklink').click(function() { DeleteLinkLink(this)});
	$('.removemisclink').click(function() { DeleteMiscLink(this)});
	$('.removeimagelink').click(function() { DeleteImageLink(this)});
	$('.uploadalbumart').click(function() {UploadAlbumArt()});
	$('.uploaddownload').click(function() {UploadPhotoGallery()});
	
	$('span.expand').toggle(function() {
	
		$(this).parent().next().next().slideToggle(600);
		$(this).html(' -');
		},
		function() {
		$(this).parent().next().next().slideToggle(600);
		$(this).html('+');}
	
	);
	var sidebarSize = $("#clientscontainer").height();
var mainContentSize = sidebarSize + 1500;
$("#clientholder").css('height', mainContentSize);
},
	error: function() {
	alert('An error occured! 472');
	}
	});
TruncateMainName();
}

function AddNewDownload() {
var newid = $('#newid').val();
//generate form code//


var html = "<div class='clientlink' style='margin-top: 15px;'>" +
			"<input name='downloads[" + newid + "][name]' type='text' id='download$this->dliterator' />" +
			"<input name='downloads[" + newid + "][title]' type='text' id='downloadtitle$this->dliterator' />" +
			"<input id='downloadid' name='downloads[" + newid + "][id]' type='hidden' value='" + newid + "' />" +
			"<input id='downloadid' name='downloads[" + newid + "][new_item]' type='hidden' value='yes' />" +

			"</div>" +
			"<img id='uploaddownload" + newid + "' class='uploaddownload' src='../images/upload.png' width='80'/>"; 

$('#newid').val(parseInt(newid, 10) + parseInt(1, 10));
$('#newdownloadforms').append(html).fadeIn(400);

};

function AddNewLink() {
var newid = $('#newid').val();

var html = "<div class='clientlink' style='margin-top: 15px;'>" +
			"<input name='link[" + newid + "][url]' type='text' id='link$this->linkiterator' />" +
			"<input name='link[" + newid + "][name]' type='text' id='link$this->linkiterator' />" +
			"<input id='linkid' name='link[" + newid + "][linkid]' type='hidden' value='" + newid + "' />" +
			"<input id='linkid' name='link[" + newid + "][new_item]' type='hidden' value='yes' />" +

			"</div>";

$('#newid').val(parseInt(newid, 10) + parseInt(1, 10));
$('#newlinkforms').append(html).fadeIn(400);

};


function AddNewMisc() {
var newmiscid = $('#newmisc').val();



var html = "<div class='clientlink' style='margin-bottom: 15px;'>" +
			"<textarea name='misc[" + newmiscid + "][content]' id='misc$this->misciterator' rows='2' cols='40' /></textarea>" +
			"<input id='miscid' name='misc[" + newmiscid + "][id]' type='hidden' value='" + newmiscid + "' />" +
			"<input id='miscid' name='misc[" + newmiscid + "][new_item]' type='hidden' value='yes' />" +
			"</div>";

$('#newmiscid').val(parseInt(newmiscid, 10) + parseInt(1, 10));
$('#newmiscforms').append(html).fadeIn(400);

};


function AddNewPhoto() {
var newphotoid = $('#newphotoid').val();

var html = "<div class='clientlink' style='margin-bottom: 15px;'>" +
"<img id='uploadphoto$uploaditerator' class='uploaddownload' src='../images/upload.png' width='80'/><br/>"+
			"URL:<br/><input style='margin-top: -1px;' name='photo[" + newphotoid + "][url]' type='text' id='photo$this->photositerator' value='paste url here'/><br/>" +
			"Title:<br/><input style='margin-top: -1px;' name='photo[" + newphotoid + "][title]' type='text' id='photo$this->photositerator' /><br/>" +
			"Caption:<br/> <input style='margin-top: -1px;' name='photo[" + newphotoid + "][caption]' type='text' id='photo$this->photositerator' /><br/>" +
			"Credit:<br/><input style='margin-top: -1px;' name='photo[" + newphotoid + "][credit]' type='text' id='photo$this->photositerator' /><br/>" +
			"<br/><br/>" +
			"<input id='photoid' name='photo[" + newphotoid + "][id]' type='hidden' value='" + newphotoid + "' />" +
			"<input id='photoid' name='photo[" + newphotoid + "][new_item]' type='hidden' value='yes' /><br/>" +

			"</div>";

$('#newphotoid').val(parseInt(newphotoid, 10) + parseInt(1, 10));
$('#newphotoforms').append(html).fadeIn(400);

$('.uploaddownload').click(function() {UploadPhotoGallery()});

};

function UpdateClientTitle() {
	if($('#descriptiontitle')) { descriptionTitle = $('#descriptiontitle').val();};
	if($('#descriptionSubTitle')) { descriptionSubTitle = $('#descriptionsubtitle').val();};
	if($('#descriptionLabel')) { descriptionLabel = $('#descriptionlabel').val();};
	if($('#rdate')) { rdate = $('#rdate').val();};
	if($('#description')) { description = $('#description').val();};
	//if($('#blurb')) { blurb = $('#blurb').val();};	
	if($('#downloadid')) {  downloadid = $('#downloadid').val();};
	if($('#linkid')) {  linkid = $('#linkid').val();};
	if($('.pastidreadout')) {  pastid = $('.pastidreadout').val();};
	if($('#miscid')) {  miscid = $('#miscid').val();};
	if($('#photoid')) { photoid = $('#photoid').val();};
	var radio = $("input[name='rdio']:checked").val();
	var daterad =$("input[name='daterad']:checked").val();
	
	
//dataToLoad = 'isCMS=' + editCMS + '&clientID=' + clientID + '&changeClient=yes' + '&project=' + descriptionSubTitle.replace(/\&/gim, '%26') + '&campaign=' + descriptionTitle.replace(/\&/gim, '%26') + '&label=' + descriptionLabel.replace(/\&/gim, '%26') + '&descriptionedit=' + description.replace(/\&/gim, '%26').replace(/<br>/gim, '') + '&blurbedit=' + blurb.replace(/\&/gim, '%26').replace(/<br>/gim, '') + '&releasedate=' + rdate.replace(/\&/gim, '%26') + '&radio=' + radio  + '&daterad=' + daterad + '&downloadid=' + downloadid + '&' + $("#download").serialize() + '&linkid=' + linkid + '&' + $('#link').serialize() + '&miscid=' + miscid + '&' + $('#misc').serialize() + '&photoid=' + photoid + '&' + $('#photos').serialize() + '&pastid=' + pastid;
dataToLoad = 'isCMS=' + editCMS + '&clientID=' + clientID + '&changeClient=yes' + '&project=' + descriptionSubTitle.replace(/\&/gim, '%26') + '&campaign=' + descriptionTitle.replace(/\&/gim, '%26') + '&label=' + descriptionLabel.replace(/\&/gim, '%26') + '&descriptionedit=' + description.replace(/\&/gim, '%26').replace(/<br>/gim, '') + '&releasedate=' + rdate.replace(/\&/gim, '%26') + '&radio=' + radio  + '&daterad=' + daterad + '&downloadid=' + downloadid + '&' + $("#download").serialize() + '&linkid=' + linkid + '&' + $('#link').serialize() + '&miscid=' + miscid + '&' + $('#misc').serialize() + '&photoid=' + photoid + '&' + $('#photos').serialize() + '&pastid=' + pastid;

	$.ajax({
	type: 'post',
	url: '/clients/controller.php',
	datatype: 'html',
	data: dataToLoad,
	async: false,
	success: function(html){
		var replaceHTML = "<div id=clientscontainer>" + html + "</div>"
		$('#clientscontainer').replaceWith(replaceHTML);
		$('#editbutton').click(function() {EditEverything()});
		dataToLoad = 'scrolloffset=' + scrolloffset + '&isCMS=' + editCMS + '&loadSidebar=yes&searchquery=' + searchQuery;
					$.ajax({
					type: 'post',
					url: '/clients/controller.php',
					datatype: 'html',
					data: dataToLoad,
					async: false,
					success: function(html){
			$('.sidebarholder').html(html);
			reExpand();
			}
			,
	error: function() {
	alert('An error occured! 222');
	}
	});	
}
})
}
;

function UploadThings(button){
$('#uploadframebacker').show(100);
	$('#uploadframebg').slideDown(600);
	
	$('#closewindow').click(function() {
		
		$('#uploadframebg').hide();
		$('#uploadframebacker').hide();
	
		$.ajax({
	type: 'post',
	url: ('/clients/controller.php'),
	datatype: 'html',
	data: dataToLoad,
	success: function(html){		
		dataToLoad = 'clientID=' + clientID + '&loadclient=yes&isCMS=' + editCMS + '&albumart=' + albumart;	
	$.ajax({
	type: 'post',
	url: '/clients/controller.php',
	datatype: 'html',
	data: dataToLoad,
	async: false,
	success: function(html){
	
		//var blurbs = $('.blurb');
		$('#clientscontainer').html(html);
		},
	error: function() {
	alert('An error occured! 222');
	}
	});},
	error: function() {
	alert('An error occured! 394');
	}});
	});
	$('#reloadwindow').click(function() {
		iframeSRC = $('#uploadframe').attr('src');
		//alert(iframeSRC);
		$('#uploadframe').attr('src', iframeSRC);
	});
	};	
	

function UploadAlbumArt(){
	$('#uploadframebacker2').show(100);
	$('#uploadframebg2').slideDown(600);
	$('#closewindow2').click(function() {
		$('#uploadframebg2').hide();
		$('#uploadframebacker2').hide();
	
		$.ajax({
	type: 'post',
	url: ('/clients/controller.php'),
	datatype: 'html',
	data: dataToLoad,
	success: function(html){		
		dataToLoad = 'clientID=' + clientID + '&loadclient=yes&isCMS=' + editCMS + '&albumart=' + albumart;	
	$.ajax({
	type: 'post',
	url: '/clients/controller.php',
	datatype: 'html',
	data: dataToLoad,
	async: false,
	success: function(html){
	
		//var blurbs = $('.blurb');
		$('#clientscontainer').html(html);
		},
	error: function() {
	alert('An error occured! 222');
	}
	});},
	error: function() {
	alert('An error occured! 394');
	}});
	});
	$('#reloadwindow2').click(function() {
		iframeSRC = $('#uploadframe2').attr('src');
		alert(iframeSRC);
		$('#uploadframe2').attr('src', iframeSRC);
	});
	};	

function UploadPhotoGallery(){
	$('#uploadframebacker3').show(100);
	$('#uploadframebg3').slideDown(600);
	$('#closewindow3').click(function() {
		$('#uploadframebg3').hide();
		$('#uploadframebacker3').hide();
	
	});
	$('#reloadwindow3').click(function() {
		iframeSRC = $('#uploadframe3').attr('src');
		alert(iframeSRC);
		$('#uploadframe3').attr('src', iframeSRC);
	});
	};	


function DeleteDownloadLink(button){

var idnumber = $(button).siblings("input[name$='[id]']").val();
var yes = confirm("Whoa there chief! Do you really want to DELETE this download form?");

	if (yes == 1) {
dataToLoad = 'deleteDownloadLink=yes&downloadid=' + idnumber;

	$.ajax({
	type: 'post',
	url: '/clients/controller.php',
	datatype: 'html',
	data: dataToLoad,
	success: function(html) {
	$(this).click(function() {reInitialize()});

	$(button).parent().add('#uploaddownload' + idnumber).remove().slideUp(800);
		},
	error: function() {
	alert('error');
	}});};};
	
function DeleteLinkLink(linkbutt){

var linkidnumber = $(linkbutt).siblings("input[name$='[linkid]']").val();

	var yes = confirm("Whoa there chief! Do you really want to DELETE this link form?");

	if (yes == 1) {
		dataToLoad = 'deleteLinkLink=yes&linkid=' + linkidnumber;
	$.ajax({
	type: 'post',
	url: '/clients/controller.php',
	datatype: 'html',
	data: dataToLoad,
	success: function(html) {
	$(this).click(function() {reInitialize()});
	$(linkbutt).parent().remove().slideUp(800);
		},
	error: function() {
	alert('error');
	}});};
};

function DeleteImageLink(imagebutt){

var imageidnumber = $(imagebutt).siblings("input[name$='[id]']").val();
alert(imageidnumber);
	var yes = confirm("Whoa there chief! Do you really want to DELETE this photo form?");

	if (yes == 1) {
		dataToLoad = 'deleteImageLink=yes&imageid=' + imageidnumber;
	$.ajax({
	type: 'post',
	url: '/clients/controller.php',
	datatype: 'html',
	data: dataToLoad,
	success: function(html) {
	$(this).click(function() {reInitialize()});
	$(imagebutt).parent().remove().slideUp(800);
		},
	error: function() {
	alert('error');
	}});};
};

function DeleteMiscLink(miscbutt){
var miscidnumber = $(miscbutt).siblings("input[name$='[id]']").val();
alert(miscidnumber);
	var yes = confirm("Whoa there chief! Do you really want to DELETE this Miscellaneous form?");

	if (yes == 1) {
dataToLoad = 'deleteMiscLink=yes&miscid=' + miscidnumber;

	$.ajax({
	type: 'post',
	url: '/clients/controller.php',
	datatype: 'html',
	data: dataToLoad,
	success: function(html) {
	
//$('#clientscontainer').html(html);
	
	$(this).click(function() {reInitialize()});

	$(miscbutt).parent().remove().slideUp(800);
		},
	error: function() {
	alert('error');
	}
	}
	);
	};
	
	};
	
function oldPost(){
	var newsPage = $('#page-number').html();
	var newsPage = newsPage / 4;
	var newsPage = newsPage + 1;
	var dataToLoad = 'newsPage=' + newsPage + '&postType=' + postCategory;
	$.ajax({
	type: 'post',
	url: '/includes/loopcat.php',
	datatype: 'html',
	data: dataToLoad,
	success: function(html) {
	
	$('#newspagefeed').html(html);
	$('#page-number').html((newsPage * 4));
	$('#olderposts').click(oldPost);
	$('#newerposts').click(newPost);
	$('.slug').click(slugClick);
	window.location.href = '#newsPage=' + newsPage + '&postType=' + postCategory;
	$('#content-holder').scrollTop(0);
		},
	error: function() {
	alert('error');
	}
	}
	);


	
};

function newPost(){
	var newsPage = $('#page-number').html();
	var newsPage = newsPage / 4;
	var newsPage = newsPage - 1;
	var dataToLoad = 'newsPage=' + newsPage + '&postType=' + postCategory;
	$.ajax({
	type: 'post',
	url: '/includes/loopcat.php',
	datatype: 'html',
	data: dataToLoad,
	success: function(html) {
	
	$('#newspagefeed').html(html);
	$('#page-number').html((newsPage * 4));
	$('#olderposts').click(oldPost);
	$('#newerposts').click(newPost);
	$('.slug').click(slugClick);
	window.location.href = '#newsPage=' + newsPage + '&postType=' + postCategory;
	$('#content-holder').scrollTop(0);
		},
	error: function() {
	alert('error');
	}
	}
	);
	

};

function slugClick(){

postCategory = $(this).attr('id');
		if (postCategory == 'everything'){postCategory = '';};
		dataToLoad = 'postType=' + postCategory;
		$.ajax({
				type: 'post',
				url: '/includes/loopcat.php',
				datatype: 'html',
				data: dataToLoad,
				async: false,
				success: function(data){
					$('#newspagefeed').html(data);
					$('#page-number').html('0');
					$('#olderposts').click(oldPost);
					$('#newerposts').click(newPost);
					$('.slug').click(slugClick);
					window.location.href = 'http://sneakattackmedia.com/news/#newsPage=0&postType=' + postCategory;
					
				}
			});

};

function setNews(){
	var newsPage;
	var found=$(location).attr('href').indexOf("#");
	if (found != -1){
	var urlSubStr=$(location).attr('href').substring((found + 1));
	var splitUrlVars=urlSubStr.split('&');
	for (x in splitUrlVars)
	{
	var found2=splitUrlVars[x].indexOf("newsPage=");
	//alert(found2);
	if (found2 != -1){
	newsPage = splitUrlVars[x].substring(9) * 4;
	}
	}
	$.ajax({
	type: 'post',
	url: '/includes/loopcat.php',
	datatype: 'html',
	data: urlSubStr,
	success: function(html) {
	
	$('#newspagefeed').html(html);
	$('#page-number').html((newsPage));
	$('#olderposts').click(oldPost);
	$('#newerposts').click(newPost);
	$('.slug').click(slugClick);
		},
	error: function() {
	alert('error');
	}
	}
	);
	}
}
