-$FATTORE_ZOOM = 10
-$ZOOM_SPEED = 0.2
-$DIMENSIONE_IMMAGINI_BEH = 90

- $behavior = $eventBehavior->behavior
- $violationCodes = $behavior->violationCodes

- $codeModels = ViolationCode::model()->filterByBehaviorId($behavior->ID)->findAll()
- $codeHash = array()
- $codeHash['']='';

- if (isset($suggestedCodes) && isset($suggestedCodes[0]) && $eventBehavior->violation_code=='')  |
  $eventBehavior->violation_code = $suggestedCodes[0]->name                |

- foreach($codeModels as $codeModel) $codeHash[$codeModel->name] = $codeModel->name

- $redData = $event->getRedData()
- $meanSpeedData = $event->getMeanSpeedData()
- $whitelistData = $event->getWhitelistData()

.event-behaviour.row(class=$behavior->isWhitelist?"whitelist-event":"whitelist-event" style="padding-top:10px;")
  != $form->hiddenField($eventBehavior, "[$index]ID")
  .span3(style="padding-left:10px;")
    .behavior-name
      %strong(title=$eventBehavior->ID)
        = Yii::t('app', $behavior->name)
        -if(user()->checkAccess('event_behavior_view'))
          %a.icon-eye-open(href="#{url('EventBehavior/view', array('id'=>$eventBehavior->ID))}")
        -if(user()->checkAccess('event_behavior_update'))
          %a.icon-pencil(href="#{url('EventBehavior/update', array('id'=>$eventBehavior->ID))}")
        -if(user()->checkAccess('event_behavior_delete'))
          %a.icon-trash(href="#{url('EventBehavior/delete', array('id'=>$eventBehavior->ID))}" onclick="return confirm('#{t('Confirm?')}');")
    - if(paramdeep('validation','viewOtherViolations'))
      - $otherViolations = $this->countOtherViolationsForPlate($event->Plate, $behavior->tag) - 1
      - if($otherViolations > 0)
        .color-red=t_by_num($otherViolations, "Found another {0} violation of this type for this plate", "Found other {0} violations of this type for this plate", array('{0}'=>$otherViolations))
    .behavior-detail(style="border: 2px solid #c3c3c3;padding: 10px;color: black;margin-top: 5px;")
      %p#Lic_Plate_final_check
        %span
          =t('License Plate')
        %span(style="float:right;font-weight: bold;")
      %p#Nationality_final_check
        %span
          =t('Nationality')
        %span(style="float:right;font-weight: bold;")
      %p#Class_final_check
        %span
          =t('Vehicle Type')
        %span(style="float:right;font-weight: bold;")
      %p#Lic_Plate_Type_final_check
        %span
          =t('License Plate Type')
        %span(style="float:right;font-weight: bold;")
      %p#SubClass_final_check
        %span
          =t('Property type')
        %span(style="float:right;font-weight: bold;")
      %p#KemlerOnu_final_check
        %span
          =t('Kemler-ONU')
        %span(style="float:right;font-weight: bold;")
      %hr
      - if ($behavior->tag == Behavior::ILLEGAL_SPOT_SPEED || $behavior->tag == Behavior::ILLEGAL_MEAN_SPEED)
        - $challengedSpeed = CalculateChallengedSpeed::run($event->Speed, Yii::app()->params['spotSpeedViolation']['percentageTolerance'], Yii::app()->params['spotSpeedViolation']['fixedTolerance'], Yii::app()->params['spotSpeedViolation']['toleranceTable']);
        .speeds-detail
          %p
            = t('Detected Speed')
            = $event->Speed
            Km/h
          %p
            %strong
              = t('Contested Speed')
              = number_format($challengedSpeed, 2)
              Km/h
          %p
            = t("Speed limit:")
            = $event->speed_limit
            Km/h
      - if (paramdeep('validation','show_trafficlight_time') && $behavior->tag == Behavior::RED_VIOLATION)
        .yellow-time-detail
          %p
            = t('Yellow Time Set')
            = $event->gate->yellow_time_set
            sec
          %p
            %strong
              = t('Measured Yellow Time')
              = number_format($redData['yellow_timegap'], 2)
              sec
  .span5      
    .behaviour-preview
      - if ($behavior->isMeanSpeed)
        - if(Yii::app()->user->checkAccess('media_view_photo'))          
          %ul(class="thumbnails")
            %li
              -if($meanSpeedData['start_bw'] != null)
                -$photo = $meanSpeedData['start_bw']
                %a(href="#{$photo->UrlEnhanced}" data-lightbox="alert-preview-#{$event->ID}" class="thumbnail")
                  -$plateRect = $photo->getPlateRectangle()
                  -if($plateRect!=null)
                    -$point = $plateRect->center
                    -$this->printAutozoomImageScaleByHeight($photo->UrlEnhanced, $photo->width, $photo->height, $DIMENSIONE_IMMAGINI_BEH, $point->X, $point->Y, $FATTORE_ZOOM, $ZOOM_SPEED)
                  -else
                    -$width_beh = ImageHelper::findScaledWidth($photo->width, $photo->height, $DIMENSIONE_IMMAGINI_BEH)
                    -$this->renderHtml("<div style=\"margin: 1px; border: 1px solid black; width: {$width_beh}px; height: {$DIMENSIONE_IMMAGINI_BEH}px;\"><img src=\"$photo->UrlEnhanced\" style=\"width: {$width_beh}px; height: {$DIMENSIONE_IMMAGINI_BEH}px;\" alt=\"\"></div>")
            %li(class="first-plate-bw")
            %li(class="first-face")
            %li
              -$photoCTX = $event->getCorrectMediaById(3000)
              -if($photoCTX != null)
                %a(href="#{$photoCTX->UrlEnhanced}" data-lightbox="alert-preview-#{$event->ID}" class="thumbnail")
                  -$width_beh = ImageHelper::findScaledWidth($photoCTX->width, $photoCTX->height, $DIMENSIONE_IMMAGINI_BEH)
                  -$this->renderHtml("<div style=\"margin: 1px; border: 1px solid black; width: {$width_beh}px; height: {$DIMENSIONE_IMMAGINI_BEH}px;\"><img src=\"$photoCTX->UrlEnhanced\" style=\"width: {$width_beh}px; height: {$DIMENSIONE_IMMAGINI_BEH}px;\" alt=\"\"></div>")
          %ul(class="thumbnails")
            %li
              -if($meanSpeedData['end_bw'] != null)
                -$photo = $meanSpeedData['end_bw']
                %a(href="#{$photo->UrlEnhanced}" data-lightbox="alert-preview-#{$event->ID}" class="thumbnail")
                  -$plateRect = $photo->getPlateRectangle()
                  -if($plateRect!=null && !$plateRect->IsEmpty)
                    -$point = $plateRect->center
                    -$this->printAutozoomImageScaleByHeight($photo->UrlEnhanced, $photo->width, $photo->height, $DIMENSIONE_IMMAGINI_BEH, $point->X, $point->Y, $FATTORE_ZOOM, $ZOOM_SPEED)
                  -else
                    -$width_beh = ImageHelper::findScaledWidth($photo->width, $photo->height, $DIMENSIONE_IMMAGINI_BEH)
                    -$this->renderHtml("<div style=\"margin: 1px; border: 1px solid black; width: {$width_beh}px; height: {$DIMENSIONE_IMMAGINI_BEH}px;\"><img src=\"$photo->UrlEnhanced\" style=\"width: {$width_beh}px; height: {$DIMENSIONE_IMMAGINI_BEH}px;\" alt=\"\"></div>")
            %li(class="second-plate-bw")
            %li(class="second-face")
            %li
              -$photoCTX = $event->getCorrectMediaById(3001)
              -if($photoCTX != null)
                %a(href="#{$photoCTX->UrlEnhanced}" data-lightbox="alert-preview-#{$event->ID}" class="thumbnail")
                  -$width_beh = ImageHelper::findScaledWidth($photoCTX->width, $photoCTX->height, $DIMENSIONE_IMMAGINI_BEH)
                  -$this->renderHtml("<div style=\"margin: 1px; border: 1px solid black; width: {$width_beh}px; height: {$DIMENSIONE_IMMAGINI_BEH}px;\"><img src=\"$photoCTX->UrlEnhanced\" style=\"width: {$width_beh}px; height: {$DIMENSIONE_IMMAGINI_BEH}px;\" alt=\"\"></div>")
      - if ($behavior->isRed)
        - if(Yii::app()->user->checkAccess('media_view_photo'))
          %br
          %table(style="width: 100%; text-align: center;")
            %tr
              %td
                -if($redData['before_bw'] != null)
                  -$photo = $redData['before_bw']
                  %a(href="#{$photo->UrlEnhanced}" data-lightbox="alert-preview-#{$event->ID}")
                    -$plateRect = $photo->getPlateRectangle()
                    -if($plateRect!=null)
                      -$point = $plateRect->center
                      -$this->printAutozoomImageScaleByHeight($photo->UrlEnhanced, $photo->width, $photo->height, $DIMENSIONE_IMMAGINI_BEH, $point->X, $point->Y, $FATTORE_ZOOM, $ZOOM_SPEED)
                    -else
                      -$width_beh = ImageHelper::findScaledWidth($photo->width, $photo->height, $DIMENSIONE_IMMAGINI_BEH)
                      -$this->renderHtml("<div style=\"margin: 1px; border: 1px solid black; width: {$width_beh}px; height: {$DIMENSIONE_IMMAGINI_BEH}px;\"><img src=\"$photo->UrlEnhanced\" style=\"width: {$width_beh}px; height: {$DIMENSIONE_IMMAGINI_BEH}px;\" alt=\"\"></div>")              
              %td                
                -if($redData['over_bw'] != null)
                  -$photo = $redData['over_bw']
                  %a(href="#{$photo->UrlEnhanced}" data-lightbox="alert-preview-#{$event->ID}")
                    -$plateRect = $photo->getPlateRectangle()
                    -if($plateRect!=null && !$plateRect->IsEmpty)
                      -$point = $plateRect->center
                      -$this->printAutozoomImageScaleByHeight($photo->UrlEnhanced, $photo->width, $photo->height, $DIMENSIONE_IMMAGINI_BEH, $point->X, $point->Y, $FATTORE_ZOOM, $ZOOM_SPEED)
                    -else
                      -$width_beh = ImageHelper::findScaledWidth($photo->width, $photo->height, $DIMENSIONE_IMMAGINI_BEH)
                      -$this->renderHtml("<div style=\"margin: 1px; border: 1px solid black; width: {$width_beh}px; height: {$DIMENSIONE_IMMAGINI_BEH}px;\"><img src=\"$photo->UrlEnhanced\" style=\"width: {$width_beh}px; height: {$DIMENSIONE_IMMAGINI_BEH}px;\" alt=\"\"></div>")              
              %td
                -if($redData['before_col'] != null)
                  -$photo = $redData['before_col']
                  %a(href="#{$photo->UrlEnhanced}" data-lightbox="alert-preview-#{$event->ID}")
                    -$plateRect = $photo->getPlateRectangle()
                    -if($plateRect!=null)
                      -$point = $plateRect->center
                      -$this->printAutozoomImageScaleByHeight($photo->UrlEnhanced, $photo->width, $photo->height, $DIMENSIONE_IMMAGINI_BEH, $point->X, $point->Y, $FATTORE_ZOOM, $ZOOM_SPEED)
                    -else
                      -$width_beh = ImageHelper::findScaledWidth($photo->width, $photo->height, $DIMENSIONE_IMMAGINI_BEH)
                      -$this->renderHtml("<div style=\"margin: 1px; border: 1px solid black; width: {$width_beh}px; height: {$DIMENSIONE_IMMAGINI_BEH}px;\"><img src=\"$photo->UrlEnhanced\" style=\"width: {$width_beh}px; height: {$DIMENSIONE_IMMAGINI_BEH}px;\" alt=\"\"></div>")              
              %td
                -if($redData['over_col'] != null)
                  -$photo = $redData['over_col']
                  %a(href="#{$photo->UrlEnhanced}" data-lightbox="alert-preview-#{$event->ID}")
                    -$plateRect = $photo->getPlateRectangle()
                    -if($plateRect!=null && !$plateRect->IsEmpty)
                      -$point = $plateRect->center
                      -$this->printAutozoomImageScaleByHeight($photo->UrlEnhanced, $photo->width, $photo->height, $DIMENSIONE_IMMAGINI_BEH, $point->X, $point->Y, $FATTORE_ZOOM, $ZOOM_SPEED)
                    -else
                      -$width_beh = ImageHelper::findScaledWidth($photo->width, $photo->height, $DIMENSIONE_IMMAGINI_BEH)
                      -$this->renderHtml("<div style=\"margin: 1px; border: 1px solid black; width: {$width_beh}px; height: {$DIMENSIONE_IMMAGINI_BEH}px;\"><img src=\"$photo->UrlEnhanced\" style=\"width: {$width_beh}px; height: {$DIMENSIONE_IMMAGINI_BEH}px;\" alt=\"\"></div>")              
              %td
                -if($redData['after_col'] != null)
                  -$photo = $redData['after_col']
                  %a(href="#{$photo->UrlEnhanced}" data-lightbox="alert-preview-#{$event->ID}")
                    -$plateRect = $photo->getPlateRectangle()
                    -if($plateRect!=null && !$plateRect->IsEmpty)
                      -$point = $plateRect->center
                      -$this->printAutozoomImageScaleByHeight($photo->UrlEnhanced, $photo->width, $photo->height, $DIMENSIONE_IMMAGINI_BEH, $point->X, $point->Y, $FATTORE_ZOOM, $ZOOM_SPEED)
                    -else
                      -$width_beh = ImageHelper::findScaledWidth($photo->width, $photo->height, $DIMENSIONE_IMMAGINI_BEH)
                      -$this->renderHtml("<div style=\"margin: 1px; border: 1px solid black; width: {$width_beh}px; height: {$DIMENSIONE_IMMAGINI_BEH}px;\"><img src=\"$photo->UrlEnhanced\" style=\"width: {$width_beh}px; height: {$DIMENSIONE_IMMAGINI_BEH}px;\" alt=\"\"></div>")              
              %td
                -if($redData['afterafter_col'] != null)
                  -$photo = $redData['afterafter_col']
                  %a(href="#{$photo->UrlEnhanced}" data-lightbox="alert-preview-#{$event->ID}")
                    -$plateRect = $photo->getPlateRectangle()
                    -if($plateRect != null && !$plateRect->IsEmpty)
                      -$point = $plateRect->center
                      -$this->printAutozoomImageScaleByHeight($photo->UrlEnhanced, $photo->width, $photo->height, $DIMENSIONE_IMMAGINI_BEH, $point->X, $point->Y, $FATTORE_ZOOM, $ZOOM_SPEED)
                    -else
                      -$width_beh = ImageHelper::findScaledWidth($photo->width, $photo->height, $DIMENSIONE_IMMAGINI_BEH)
                      -$this->renderHtml("<div style=\"margin: 1px; border: 1px solid black; width: {$width_beh}px; height: {$DIMENSIONE_IMMAGINI_BEH}px;\"><img src=\"$photo->UrlEnhanced\" style=\"width: {$width_beh}px; height: {$DIMENSIONE_IMMAGINI_BEH}px;\" alt=\"\"></div>")              
      - if ($behavior->isWhitelist)
        - if(Yii::app()->user->checkAccess('media_view_photo'))
          %br
          %table(style="width: 100%; text-align: center;")
            %tr
              %td
                - if($whitelistData['reference_bw'] != null)
                  - $photo = $whitelistData['reference_bw']
                  %a(href="#{$photo->UrlEnhanced}" data-lightbox="alert-preview-#{$event->ID}")
                    - $plateRect = $photo->getPlateRectangle()
                    - if($plateRect!=null)
                      - $point = $plateRect->center
                      - $this->printAutozoomImageScaleByHeight($photo->UrlEnhanced, $photo->width, $photo->height, $DIMENSIONE_IMMAGINI_BEH, $point->X, $point->Y, $FATTORE_ZOOM, $ZOOM_SPEED)
                    - else
                      - $width_beh = ImageHelper::findScaledWidth($photo->width, $photo->height, $DIMENSIONE_IMMAGINI_BEH)
                      - $this->renderHtml("<div style=\"margin: 1px; border: 1px solid black; width: {$width_beh}px; height: {$DIMENSIONE_IMMAGINI_BEH}px;\"><img src=\"$photo->UrlEnhanced\" style=\"width: {$width_beh}px; height: {$DIMENSIONE_IMMAGINI_BEH}px;\" alt=\"\"></div>")
              %td
                - if($whitelistData['reference_col'] != null)
                  - $photo = $whitelistData['reference_col']
                  %a(href="#{$photo->UrlEnhanced}" data-lightbox="alert-preview-#{$event->ID}")
                    - $plateRect = $photo->getPlateRectangle()
                    - if($plateRect!=null && !$plateRect->IsEmpty)
                      - $point = $plateRect->center
                      - $this->printAutozoomImageScaleByHeight($photo->UrlEnhanced, $photo->width, $photo->height, $DIMENSIONE_IMMAGINI_BEH, $point->X, $point->Y, $FATTORE_ZOOM, $ZOOM_SPEED)
                    - else
                      - $width_beh = ImageHelper::findScaledWidth($photo->width, $photo->height, $DIMENSIONE_IMMAGINI_BEH)
                      - $this->renderHtml("<div style=\"margin: 1px; border: 1px solid black; width: {$width_beh}px; height: {$DIMENSIONE_IMMAGINI_BEH}px;\"><img src=\"$photo->UrlEnhanced\" style=\"width: {$width_beh}px; height: {$DIMENSIONE_IMMAGINI_BEH}px;\" alt=\"\"></div>")              
      - if ($eventBehavior->preview !== null)
        - $preview = $eventBehavior->preview
        %span
          %i.icon-file-alt
          %a(href="#{Yii::app()->createAbsoluteUrl('event/violationDocumentPreview', array('violationDocumentId' => $preview->id))}" target="_blank")= Yii::t('app', 'Violation Preview')
      
      - elseif(paramdeep('validation','viewAllViolationDocuments'))
        -$violationDocuments = $eventBehavior->violationDocuments
        -foreach($violationDocuments as $vdoc)
          %span
            %i.icon-file-alt
            %a(href="#{url('event/violationDocumentPreview', array('violationDocumentId' => $vdoc->id))}" target="_blank")= Yii::t('app', 'Violation Document')
    %p.violation-code-description(id="eventBehavior-#{$eventBehavior->ID}-description")
      - if (isset($suggestedCodes) && isset($suggestedCodes[0]))
        ="{$suggestedCodes[0]->description}"

  .span3
    .violation-code
      
      != $form->dropDownList($eventBehavior, "[$index]violation_code", $codeHash, array('id' => 'eventBehavior-'.$eventBehavior->ID.'-code', 'class' => 'span4 chzn-select violation-code-select', 'data-placeholder' => Yii::t('app','Choose code'), 'data-event-behavior-id' => $eventBehavior->ID, 'data-event-tag' => $behavior->tag,'style'=>"width: 250px;"))
      - if (($error = $eventBehavior->getError('violation_code')) !== null)
        %span.help-inline.error= $error

      %button.btn(type="button"
        data-behavior="AjaxModal"
        data-ajax-modal-target="#modal-violation-code-suggestion"
        data-ajax-modal-url="#{Yii::app()->createAbsoluteUrl('spotSpeedArticleWizard/view', array('idEventBehavior' => $eventBehavior->ID))}"
        data-ajax-modal-form-serialize="#event-form")
        = Yii::t('app', 'Suggest code')

    .violation-comment
      -if(paramdeep('validation', 'comment', 'autocomplete','enabled'))
        -if(paramdeep('validation', 'comment', 'autocomplete','dropdown'))
          -$comments = $this->getCommentSuggestions()
          != $form->dropDownList($eventBehavior, "[$index]comment", $comments, array('class' => 'span4 chzn-select', 'data-placeholder' => Yii::t('app', 'Insert comment...'),'style'=>"width: 250px;"))
        -else
          -$script = $this->getCommentSuggestionsJS()
          -if($script != null)
            != $script
            != $form->textField($eventBehavior, "[$index]comment", array('class' => 'span4 autocomment', 'placeholder' => Yii::t('app', 'Insert comment...'),'style'=>"width: 250px;"))
      -else
        != $form->textField($eventBehavior, "[$index]comment", array('class' => 'span4', 'placeholder' => Yii::t('app', 'Insert comment...'),'style'=>"width: 250px;"))

    .violation-buttons.btn-group(data-toggle="buttons-radio")
      != $form->hiddenField($eventBehavior, "[$index]validation_result", array('id' => 'event-behavior-status-'.$eventBehavior->ID))
      %button.btn-status.btn-status-approved.btn(type="button" class=$eventBehavior->isApproved()?"active btn-success":"" data-event-behavior-id="#{$eventBehavior->ID}" data-class-color="btn-success" data-status="#{EventBehavior::STATUS_APPROVED}")
        %i.icon-thumbs-up
        = Yii::t("app", "Approved")
      %button.btn-status.btn-status-pending.btn(type="button" class=$eventBehavior->isPending()?"active btn-warning":"" data-event-behavior-id="#{$eventBehavior->ID}" data-class-color="btn-warning" data-status="#{EventBehavior::STATUS_PENDING}")
        %i.icon-time
        = Yii::t("app", "Pending")
      %button.btn-status.btn-status-invalid.btn(type="button" class=$eventBehavior->isInvalid()?"active btn-danger":"" data-event-behavior-id="#{$eventBehavior->ID}" data-class-color="btn-danger" data-status="#{EventBehavior::STATUS_INVALID}")
        %i.icon-remove
        = Yii::t("app", "Invalid")
      - if(paramdeep('validation','voidButton','enabled'))
        %button.btn-status.btn-status-void.btn(type="button" class=$eventBehavior->isVoid()?"active btn-void":"" data-event-behavior-id="#{$eventBehavior->ID}" data-class-color="btn-void" data-status="#{EventBehavior::STATUS_VOID}")
          %i.icon-meh
          = Yii::t("app", "Void")
    - if (($error = $eventBehavior->getError('validation_result')) !== null)
      %span.help-inline.error= $error

#modal-violation-code-suggestion.modal.hide.fade
#modal-whitelist-import-running.modal.hide.fade
