











/**
 * 
 * Main script for sliding images in #imageblock
 * 
 * 
 */



$(document).ready(function(){
  
  
  // imageBlockSetup();
  /*
  $('.links span').click(function(){
    
    if (sliding) return;
    
    sliding = true;
    
    imageBlockSlide(imageslidearray[0]);
    
  });
  */
  
  // alert($('#imageslide .slideitem').length);
  
  
  
  
  // * Script facebook block ie fix ...
  
  
  if ( jQuery.browser.msie && (jQuery.browser.version == '6.0' || jQuery.browser.version == '7.0') ){
    
    
    var fb = '<div style="clear:both;"><iframe src="http://www.facebook.com/plugins/likebox.php?href=http%3A%2F%2Fwww.facebook.com%2Fpages%2FSandazh%2F186294168075409&amp;width=182&amp;colorscheme=light&amp;show_faces=true&amp;stream=false&amp;header=false&amp;height=280" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:182px; height:280px;" allowTransparency="true"></iframe></div>';
    
    $('#facebook_block').html(fb);
    
  }
  
  
  
});




var sliderate = 2000;

var imagearray = [];
var index = 0;


function imageBlockSlideArray(array){
  
  imagearray = array;
  index = 0;
  
  imageBlockSlideFirst();
  
}


function imageBlockSlideFirst(){
  
  clearTimeout(timerindex);
  
  //imageBlockSlide(imagearray[index], imageBlockSlideNext);
  
  imageBlockFade(imagearray[index], function(){if (imagearray.length > 1) imageBlockSlideNext();});
  
  
}


var timerindex = 0;

function imageBlockSlideNext(start){
  
  
  //if (start) clearTimeout(timerindex);
  
  
  timerindex = setTimeout(function(){
    
    
    if (imagearray.length > index + 1) index++; else index = 0;
    
    //imageBlockSlide(imagearray[index], function(){imageBlockSlideNext();});
    imageBlockSlideDiv(imagearray[index], function(){imageBlockSlideNext();});
    
    
  }, sliderate);
  
  
}



var sliding = false;
//var slideval = -230;
var slideval = -205;
var slidetime = 2000;


function imageBlockSlide(url, callback){
  
  
  if (sliding) {
    
    //$('#imageblock .slideitem').stop().css('top', 0);
    //$('#imageblock .upper').css('background-image', $('#imageblock .lower').css('background-image'));
    
    sliding = false;
    
    $('#imageblock .slideitem').stop().css('top', 0);
    $('#imageblock .upper').css('background-image', 'url(' + url + ')');
    
    if (callback) callback();
    
    return;
  }
  
  
  var dblcall = false; // disables second callback
  
  sliding = true;
  
  
  $('#imageblock .lower').css('background-image', 'url(' + url + ')');
  
  $('#imageblock .slideitem').animate({top: slideval}, slidetime, null, function(){
    
    $('#imageblock .upper').css('background-image', 'url(' + url + ')');
    
    $('#imageblock .slideitem').css({top: 0});
    
    
    sliding = false;
    
    
    // !IMP. since we animating two slides (.upper and .lower [.slideitem])
    // there's two callbacks.
    
    if (!dblcall && callback) {
      
      dblcall = true;
      
      callback();
    }
    
  });
  
}






var sliding = false;
var _slideval = -205;
var _slidetime = 2000;


function imageBlockSlideDiv(url, callback){
  
  
  if (sliding) {
    
    sliding = false;
    
    $('#imageblock .slideholder').stop().css('top', 0);
    $('#imageblock .upper').css('background-image', 'url(' + url + ')');
    
    if (callback) callback();
    
    return;
  }
  
  
  
  sliding = true;
  
  
  $('#imageblock .lower').css('background-image', 'url(' + url + ')');
  
  $('#imageblock .slideholder').animate({top: _slideval}, slidetime, null, function(){
    
    $('#imageblock .upper').css('background-image', 'url(' + url + ')');
    
    $('#imageblock .slideholder').css({top: 0});
    
    
    sliding = false;
    
    callback();
    
  });
  
  
}








function imageBlockFade(url, callback){
  
  
  // ending slide animation if any
  clearTimeout(timerindex);
  sliding = false;
  
  $('#imageblock .slideholder').stop().css({top: 0});
  
  //$('#imageblock .layerslide').addClass('onfade');
  
  //$('#imageblock .upper').css({opacity: 0, 'background-image': 'url(' + url + ')'});
  $('#imageblock .upper').css({'background-image': 'url(' + url + ')'});
  $('#imageblock .slideholder').css({opacity: 0});
  
  $('#imageblock .slideholder').animate({opacity: 1}, 1000, null, function(){
    
    //$('#imageblock .layerslide').removeClass('onfade');
    
    if (callback) callback();
    
  });
  
}



function imageBlockSetup(){
  
  
}








/**
 * 
 * Wrapping CITEs by js
 * 
 */


$(document).ready(function(){
  
  
  $('.pagetitle').html($('#szh_page_cite').val());
  
});









/**
 * 
 * Script for page - YOU
 * 
 * switches logos on $(.links span) press.
 * 
 */


$(document).ready(function(){
  
  
  if(typeof(youpageobject) != 'undefined') {
    
    
    var array = [];
    
    for(var index in youpageobject){
      
      if (youpageobject[index]['image'][0]){
        
        array.push(youpageobject[index]['image'][0]);
      }
    }
    
    imageBlockSlideArray(array);
    
    //$('#' + firstid).addClass('active');
    //imageBlockSlide(youpageobject[1].image);
    //imageBlockFade(youpageobject[1].image);
    //imageBlockSlideArray(youpageobject[firstid].image);
    
    
    $('.links span').click(function(){
      
      
      if ($(this).hasClass('active')) return;
      
      
      $('.links .active').removeClass('active');
      
      $(this).addClass('active');
      
      
      //imageBlockFade(youpageobject[$(this).attr('id')].image);
      
      //imageBlockSlide(youpageobject[$(this).attr('id')].image);
      
      imageBlockSlideArray(youpageobject[$(this).attr('id')].image);
      
      
    });
    
    
  }
  
  
});




/**
 * 
 * Script for page - WANT
 * 
 * switches logos on $(.links span) press.
 * 
 */


$(document).ready(function(){
  
  
  if(typeof(wantpageobject) != 'undefined') {
    
    
    $('#' + firstid).addClass('active');
    
    imageBlockSlideArray(wantpageobject[firstid].image);
    
    $('#infoformat').text(wantpageobject[firstid].format);
    $('#infoclient').text(wantpageobject[firstid].client);
    $('#infolocation').text(wantpageobject[firstid].location);
    
    
    $('.links span').click(function(){
      
      
      if ($(this).hasClass('active')) return;
      
      
      $('.links .active').removeClass('active');
      
      $(this).addClass('active');
      
      
      imageBlockSlideArray(wantpageobject[$(this).attr('id')].image);
      
      $('#infoformat').text(wantpageobject[$(this).attr('id')].format);
      $('#infoclient').text(wantpageobject[$(this).attr('id')].client);
      $('#infolocation').text(wantpageobject[$(this).attr('id')].location);
      
      
    });
    
    
  }
  
  
});







/**
 * 
 * Script for page - NEW
 * 
 * switches logos on $(.textblock span) press.
 * 
 */


$(document).ready(function(){
  
  
  if(typeof(newpageobject) != 'undefined') {
    
    
    $('#' + firstid).addClass('active');
    $('#' + firstid).parent().parent().children('.textcontent').addClass('active');
    
    imageBlockSlideArray(newpageobject[firstid].image);
    
    
    $('.textblock span').click(function(){
      
      
      if ($(this).hasClass('active')) return;
      
      
      $('.textblock .active').removeClass('active');
      
      $(this).addClass('active');
      $(this).parent().parent().children('.textcontent').addClass('active');
      
      imageBlockSlideArray(newpageobject[$(this).attr('id')].image);
      
      
    });
    
    
  }
  
  
});









/**
 * 
 * Script for page - CONTACT
 * 
 * 
 */


$(document).ready(function(){
  
  
  if (jQuery.browser.msie && (jQuery.browser.version == '6.0')){
    
    $('#counterblock .roll').parent().html($('#counterblock .roll .lower').html());
    return;
  }
  
  $('#counterblock .upper, #counterblock .lower').animate({top: -48}, 2000);
  
  
});





/**
 * 
 * Script for page - ARTICLES and NEWS
 * 
 * 
 */


$(document).ready(function(){
  
  
  
  if(typeof(postspageobject) != 'undefined') {
    
    
    $('#' + firstid).addClass('active');
    imageBlockSlideArray(postspageobject[firstid].image);
    
    
    $('.pageposts .post').mouseover(function(){
      
      
      if ($(this).hasClass('active')) return;
      
      $('.pageposts .post.active').removeClass('active');
      
      $(this).addClass('active');
      
      imageBlockSlideArray(postspageobject[$(this).attr('id')].image);
      
    });
    
    
    
    $('.pageposts .post').mouseout(function(){
      
      // $(this).removeClass('active');
    });
    
    
  }
  
  
});




/**
 * 
 * Script for page - ARTICLES and NEWS  -   CONTENT
 * 
 * 
 */


$(document).ready(function(){
  
  
  
  if(typeof(articlecontentobject) != 'undefined') {
    
    
    imageBlockSlideArray(articlecontentobject[firstid].image);
    
    
  }
  
  
});







// Script for switching pages ing YOU, WANT & NEW


$(document).ready(function(){
  
  
  
  $('.szh_js_pages_list span').click(function(){
    
    
    var active = $('#szh_js_page_active').val();
    var count = $('#szh_js_page_count').val();
    
    var gotoid = active;
    
    
    if($(this).text() == '>'){
      
      if(active < count) {
        
        active++;
        $('.szh_js_pages_list span').removeClass('active');
        $('#szh_js_page_active').val(active);
        $('#szh_js_page_bt_' + active).addClass('active');
        gotoid = active;
        
      } else {
        
        //$(this).addClass('out');
        
      }
      
    } else if($(this).text() == '<'){
      
      if(active > 1) {
        
        active--;
        $('.szh_js_pages_list span').removeClass('active');
        $('#szh_js_page_active').val(active);
        $('#szh_js_page_bt_' + active).addClass('active');
        gotoid = active;
        
      } else {
        
        //$(this).addClass('out');
        
      }
      
    } else {
      
      $('.szh_js_pages_list span').removeClass('active');
      
      active = $(this).text();
      
      $('#szh_js_page_active').val(active);
      $('#szh_js_page_bt_' + active).addClass('active');
      
      $(this).addClass('active');
      gotoid = active;
      
    }
    
    
    if(active == 1){
      $('.arrow').removeClass('out');
      $('.arrow_left').addClass('out');
    } else if(active == count) {
      $('.arrow').removeClass('out');
      $('.arrow_right').addClass('out');
    } else {
        $('.arrow').removeClass('out');
    }
    
    
    $('.szh_js_page').removeClass('open');
    $('#szh_js_page_index_' + gotoid).addClass('open');
    
    
  });
  
  
});





// Javascript Redirect SEO ...

$(document).ready(function(){
  
  $('.szh_js_redirect').click(function(){
    
    
    window.location = $(this).children('input').val();
    
  });
});







// Script for gallery


$(document).ready(function(){
  
  
  // checking if its gallery page
  
  if( !$('#gallery_page').val() ) return;
  
  
  
  var createnav = function(){
    
    
    $('.page_gallery .group_title').each(function(index){
      
      
      $(this).data().index = index;
      
      
      var $span = $('<span/>');
      
      $span.attr('title', $(this).text());
      
      $span.data().index = index;
      $span.data().link = $(this);
      
      $('.gallery_awsome_nav').append($span);
      
      
      if (index == 0) $span.addClass('active');
      
      //console.log(index);
      
    });
    
    
  }
  
  
  createnav();
  
  
  
  // disabling selections
  
  $('.gallery_awsome_nav').onselectstart = function() { return false; };
  
  
  
  $('.gallery_awsome_nav span:not(.active)').css({opacity: 0.6});
  
  
  $('.gallery_awsome_nav span').mouseover(function(){
    
    if( !$(this).hasClass('active') ) $(this).css({opacity:1});
  });
  
  
  $('.gallery_awsome_nav span:not(.active)').mouseout(function(){
    
    if( !$(this).hasClass('active') ) $(this).css({opacity:0.6});
  });
  
  
  
  
  $('.gallery_awsome_nav span').click(function(){
    
    
    if( $(this).hasClass('active') ) return;
    
    var span = $(this);
    
    //$('.gallery_awsome_nav span').removeClass('active');
    //span.addClass('active');
    //span.css({opacity: 1});
    
    var index = $(this).data().index;
    
    
    if (index == 0) {
      
      if( $(window).scrollTop() != 0 ){
        
        $('.gallery_awsome_nav span').removeClass('active');
        
        $('html,body').stop().animate({scrollTop: 0}, 1000, null, function(){
          
          span.addClass('active');
          span.css({opacity: 1});
        });
      }
      
    } else {
      
      
      $('.page_gallery .group_title').each(function(){
        
        if(index == $(this).data().index){
          
          
          var _window = $(window);
          var delta = 20;
          
          var wtop = _window.scrollTop();
          var btop = $(this).position().top;
          
          
          if ( btop != wtop ){
            
            $('.gallery_awsome_nav span').removeClass('active');
            
            $('html,body').stop().animate({scrollTop: btop}, 1000, null, function(){
              
              span.addClass('active');
              span.css({opacity: 1});
              
            });
            
            //_window.scrollTop(btop);
            //console.log(btop);
            
          }
          
        }
        
      });
      
    }
    
    
  });
  
  
  
  $(window).scroll(function(){
    
    
    var wtop = $(window).scrollTop();
    var delta = 100;
    
    $('.page_gallery .group_title').each(function(){
      
      var group = $(this);
      var btop = group.position().top;
      
      if( wtop + delta > btop ){
        
        $('.gallery_awsome_nav span').each(function(){
          
          var span = $(this);
          
          if( span.data().index == group.data().index ){
            
            $('.gallery_awsome_nav span').removeClass('active').css({opacity: 0.6});
            span.addClass('active');
            span.css({opacity: 1});
            
          }
          
        });
        
      }
      
    });
    
    
    //console.log('+1');
    
  });
  
  
  
  
  
});




















