/**
 * @author Dmitri
 */
var outerSlide = 0;
var innerSlide = 0;
var blockSlide         = false;
var userTimeout        = false;
var slideTimeoutObject = false;
var slideTimeoutSec    = 7;
var tmpOuterIndex      = 0;
var tmpInnerIndex      = 0;


function pathOnly(InString) {
  var LastSlash = InString.lastIndexOf ('/', InString.length-1)
  var OutString = InString.substring(LastSlash+1) 
  return (OutString);  
}


function startSlide()
{
  slideTimeoutObject = setTimeout("slideInner()", slideTimeoutSec*1000);
  $("div#outer_slides a, div.inner_slides a.inner_thumb img").bind("mousedown", function(e)
  {
    blockSlide = true;
    if (slideTimeoutObject!==false) { slideTimeoutObject = clearTimeout(slideTimeoutObject); slideTimeoutObject = false; }
    if (userTimeout!==false) { userTimeout = clearTimeout(userTimeout); userTimeout = false; }
    userTimeout = setTimeout(function() { blockSlide = false; slideInner(); }, slideTimeoutSec*4000);
  });
}


function slideInner()
{
  tmpInnerIndex = (innerSlide==3) ? 0 : innerSlide + 1;
  if (innerSlide==3)
  {
    tmpOuterIndex = (outerSlide==2) ? 0 : outerSlide + 1;
    //if (tmpOuterIndex==0) { outerSlide = 0; innerSlide = 0; }
    $("div#outer_slides li").eq(tmpOuterIndex).children("a").click();
    setTimeout(function() { $("div.inner_slides").eq(tmpOuterIndex).find("li").eq(0).children("a").click(); }, 500);
    if (slideTimeoutObject!==false) { slideTimeoutObject = clearTimeout(slideTimeoutObject); slideTimeoutObject = false; }
    slideTimeoutObject = setTimeout("slideInner()", slideTimeoutSec*1000);
  }
  else $("div.inner_slides").eq(tmpOuterIndex).find("li").eq(tmpInnerIndex).children("a").click();
}
 
$(function()
{
	/*
	var fgpsResponse = null;
	$.ajax({
  	url: "http://moniquepean.fashiongps.com/internal/ecommerce.php",
		data: 'r={"auth":"wyoaJHJUasa5a2ZFh2J4JsT24qTqZoJF1z6uk3usmxafnJntjZF1MeSF","request":"get_all_saleable"}',
		crossDomain: true,
		dataType: "json",
		async: false,
		global: false,
		success: function(data) {
    	if (console.log)
			{
				console.log("Request response successfully parsed");
				fgpsResponse = data;
				$.each(fgpsResponse, function(k,v){
					console.log(k,v);
					$.each(v, function(k2,v2)
					{
						console.log(k2,v2);
					});
				});
			}
		},
    error: function (XMLHttpRequest, textStatus, errorThrown) {
    	if (console.log) console.log("Error processing request: "+errorThrown);
    },
  	complete: function(data){
    	if (console.log) console.log("Request completed"); 
  	}
	});
	*/
  
  var hoverTimeOut = null;
  
  $('#main_navigation').children('li').children("a[href='process.php']").hover(function(){
    // set features sub_navigation position
    var featuresPosition = $(this).position();
    $('#sub_navigation').css("left",featuresPosition.left);
    if ($("#sub_navigation:visible").length != 0)
    {
      window.clearTimeout(hoverTimeOut);
      hoverTimeOut = false;
    }
    else $("#sub_navigation").fadeIn(200);
  },
  function(){
    if ($(this).parent('li').parent('ul').attr("id") != 'main_navigation') return;
    hoverTimeOut = window.setTimeout(function(){
      $("#sub_navigation").fadeOut(200);
    },50);
  });
  
  $('#sub_navigation').bind('mouseenter',function(){
    window.clearTimeout(hoverTimeOut);
  }).bind('mouseleave',function(){
    hoverTimeOut = window.setTimeout(function(){
      $("#sub_navigation").fadeOut(200);
    },50);
  });
  
  
  var urlRelPath = pathOnly(window.location.pathname);
  $("a[href='"+urlRelPath+"']").css('color','#ff0099');
  if ($("#sub_navigation").length > 0) {$("#navigation a[href='process.php']").css('color','#ff0099');}
  
  $(".tweet").tweet({
    username: "fashiongps",
    join_text: "auto",
    avatar_size: 0,
    count: 20,
    auto_join_text_default: "we said,",
    auto_join_text_ed: "we",
    auto_join_text_ing: "we were",
    auto_join_text_reply: "we replied to",
    auto_join_text_url: "we were checking out",
    loading_text: "loading tweets..."
  });
  
  $('.image_gallery').cycle({
    fx:  'fade',
    speed:  'slow', 
    timeout: 0, 
    next:   '#next', 
    prev:   '#prev',
    before:  onBefore
  });
  
  $('.processpageimages').cycle({
    fx:        'fade',
    speed:     'slow',
    timeout:   6000
  });
  
  $('.cycle').cycle({
    fx: 'fade',
    speed: 'slow'
  });

  $('.client_logos').cycle({
    fx:    'fade',
    speed:  'slow',
    timeout: 6000
  });

  function onBefore() {
    $('#caption').html(this.alt);
  }
  
  $('.old_contact').validate({ debug: false });
  
  $("#contact_submit").bind("click", function(){ $('#old_contact_form').submit(); });


  // set up the dynamic switching of text based on which slide is selected
  // slideText is an array of 3 features, with 4 inner thumbnail slides each
  var slideText = new Array(new Array(4), new Array(4), new Array(4), new Array(4));
  
	slideText[0][0] = "GPS Radar is a global platform that connects the fashion industry and makes managing events even easier.   <strong>For Fashion Brands, Merchandisers and Agencies:</strong> GPS Radar helps you keep your virtual rolodex up-to-date and connected to the people who drive your business. <strong>For Fashion Media, Creative Support Professionals and Tastemakers:</strong>  GPS Radar connects you to the world's leading fashion brands and PR agencies and lets you be the first to enjoy exclusive access to the largest digital fashion community worldwide. Plus: manage all your RSVPs from one convenient website and keep your information up-to-date with all FGPS member fashion brands and PR houses, ensuring you never miss event invitations and other communications.";
	slideText[0][1] = "Invitees can RSVP to all their events from one convenient website, or give their assistant or team coordinator access to manage their schedules on their behalf.  Events can be viewed by day, week, month for one stop schedule management.  The built-in Events Map offers a quick visual overview and makes plotting out the day a cinch.   Barcodes for digital check-in are emailed or printed with a single click. ";
	slideText[0][2] = "<strong>For Fashion Media, Creative Support Professionals and Tastemakers:</strong> The GPS Radar Mobile App for iPhone is your digital companion for events management on-the-go.  Featuring built-in RSVPing, Events Map and Barcodes on Demand for speedy digital check-in. <a target='_blank' href='http://itunes.apple.com/us/app/fashion-gps-radar/id461086926?mt=8&ign-mpt=uo%3D4'>Available in the iTunes store</a>";
	
  slideText[1][0] = "<strong>For Press &mdash; </strong> GPS Styles  is a powerful digital library of web and print-ready imagery.  Robust Keyword search and e-commerce-style filters help you quickly find and download designer imagery for color stories, trend features, mood boards and fashion editorials. Multi-image selection and 1-click download.  Completely FREE, available 24/7 with pre-loaded stockist and pricing information.  Your image research, reduced to a matter of keystrokes.";
  slideText[1][1] = "<strong>For Companies</strong> &mdash;  Create, archive and publish press-ready web galleries with high-resolution previews and detailed annotations.  Store all of your Product, Look & Campaign Images, Press Releases, and Clippings in one convenient system. Unlike traditional Digital Asset Managers, GPS Styles is fully integrated with GPS Samples to streamline workflow and act as a powerful, centralized visual inventory for managing your PR needs.";
  slideText[1][2] = "Your Digital Asset Management tool for centralized storage, management and distribution of media files. Robust file and folder management system intelligently archives seasonal fashion images and press clippings. Supports a wide range of file formats including JPEG, GIF, PNG, TIFF and PDF. Instantly maximize editorial exposure by making your product images & look books accessible to key industry press from one convenient portal.";
  slideText[1][3] = "Your One Stop Shop for Sample and Image requests. Quick, easy, and effective to use, GPS Styles also offers a built-in Press Center. Key brand press contacts and social media are consolidated and displayed in one convenient place, alongside the latest press releases. ";
  
  slideText[2][0] = "<strong>In partnership with IMG Fashion</strong> Fashion GPS is available for all Mercedes-Benz Fashion Week shows at Lincoln Center.  Manage your invitee list, send electronic invitations, digitally collect RSVP status, and virtually seat color-coded attendees.  GPS Events simplifies each step of the events process using cutting edge technologies.";
  slideText[2][1] = "No barcode? No problem.  Designer desks manage guests quickly with instant invitee search, complete without the ability to add guests and print seating assignments.  Last minute changes are a breeze with real-time check in information, placing empty seats at your fingertips.";
  slideText[2][2] = "Obtaining seating assignments is a breeze: guests simply scan barcodes at the tents to obtain the seating assignment.  Credentialed media personnel scan their badges to obtain the day's shows &ndash; long check in lines are so last season.";
  slideText[2][3] = "Generate reports of attendees &ndash; even before the event ends.  Attach pictures to your list for instant recognition.";
  
  slideText[3][0] = "Search invitees by name, affiliation, or simply browse your list &ndash; complete with pictures, tapping to check in.  Sync-and-go functionality allows guest list access anywhere, online or off.  Queueing capabilities means never losing track of your attendees.";
  slideText[3][1] = "Ensure correct seating assignments with live seating information directly on your iPad.  Seat unseated attendees or check them in directly from your seating chart.  Coordinate VIP seating and add guests with a few taps.";
  slideText[3][2] = "Not enough to have your entire RSVP list and seating chart at the event?  Upload any extra documents from our web portal and access them directly from the iPad.  Won't have internet on site?  Download the documents within the app for later viewing.";
  slideText[3][3] = "Wireless Bluetooth&trade; scanning capabilities allow for a portable checkin solution:  your checkin station is now an iPad or iPod touch and a wireless scanner.  The scanning area can now be backstage, front of house, or anywhere in between. Eco friendly, reliable, and intuitive: your events solution, now made portable.";
  
  $('#bottom_panel').html(slideText[outerSlide][innerSlide]);
  
  $('#outer_slides').slides({
    preload: true,
    preloadImage: './images/loading.gif',
    play: 0,
    pause: 0,//1500,
    slideSpeed: 450,
    effect: 'fade',
    generatePagination: false,
    animationStart: function(){
      $('#bottom_panel').fadeOut(50);
    },
    animationComplete: function(obj){
      var currentInner = parseInt($('div.slides_control div:visible').find('li[class=current] a').attr("href").replace("#",""));
      outerSlide = obj-1;
      innerSlide = currentInner;
      $('#bottom_panel').html(slideText[outerSlide][innerSlide]).fadeIn(150);
      
    }
  });
  
  $('.inner_slides').slides({
    preload: true,
    preloadImage: './images/loading.gif',
    container: 'inner_slides_container',
    play: 0,
    pause: 0,
    slideSpeed: 600,
    effect: 'fade',
    generatePagination: false,
    pagination: true,
    bigTarget: false,
    paginationClass: 'inner_pagination',
    paginationClass2: 'inner_pagination',
    animationStart: function(){
      $('#bottom_panel').fadeOut(50);
    },
    animationComplete: function(obj){
      innerSlide = obj-1;
      $('#bottom_panel').html(slideText[outerSlide][innerSlide]).fadeIn(150);

      if (slideTimeoutObject!==false) { slideTimeoutObject = clearTimeout(slideTimeoutObject); slideTimeoutObject = false; }
      if (!blockSlide) slideTimeoutObject = setTimeout("slideInner()", slideTimeoutSec*1000);
    }
  });
  
  $('#client_slides').slides({
    preload: true,
    preloadImage: './images/loading.gif',
    play: 0,
    pause: 1500,
    slideSpeed: 450,
    effect: 'fade'
  });
  
  //startSlide();
});

